1.依赖包安装
yum install gdb gcc gcc-c++ ncurses-devel cmake libaio bison zlib-devel openssl openssl-devel patch
2.下载MysqL源码包和boost库
- 下载最新MysqL源码
https://cdn.MysqL.com//Downloads/MysqL-5.7/MysqL-boost-5.7.18.tar.gz
- 下载boost库,版本 boost_1_59_0
http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.bz2
MysqL-8.0需要boost_1_63_0版本
3.上传并解压
上传并解压安装包:
[root@localhost MysqL]# tar -xzvf MysqL-boost-5.7.18.tar.gz
[root@localhost MysqL]# tar -xzvf boost_1_59_0.tar.bz2
4 建立MysqL用户和组,建立相关目录
/usr/sbin/groupadd MysqL
/usr/sbin/useradd MysqL -g MysqL -d /home/MysqL -s /sbin/nologin
mkdir /home/MysqL/data/3306/data
mkdir /home/MysqL/data/3306/log
mkdir /home/MysqL/data/3306/tmp
mkdir /home/MysqL/data/3306/binlog
创建MysqL安装目录
mkdir /usr/local/MysqL chown -R MysqL.MysqL /usr/local/MysqL chown -R MysqL.MysqL /home/MysqL
5 编译MysqL源码&安装MysqL
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \
-DMysqL_DATADIR=/home/MysqL/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_EDITLINE=bundled \
-DMysqL_UNIX_ADDR=/home/MysqL/MysqL.sock \
-DMysqL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_DEBUG=1 \
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/xxx/xxx/boost_1_59_0 -DDOWNLOAD_BOOST_TIMEOUT=60000
编译
make
根据机器配置等待一段时间,看到100%字样,则说明编译成功
安装到 /usr/local/MysqL 目录下
make install
6.配置MysqL环境变量
在/etc/profile中添加/usr/local/MysqL/bin到PATH变量中
PATH=/usr/local/MysqL/bin:$PATH
执行source /etc/profile 生效
7.初始化MysqL数据库
初始化data文件
MysqLd --defaults-file=/home/MysqL/data/3306/my.cnf --initialize-insecure --user=MysqL --basedir=/usr/local/MysqL --datadir=/home/MysqL/data/3306/data
su - MysqL
MysqL_ssl_rsa_setup --user=MysqL --basedir=/usr/local/MysqL --datadir=/home/MysqL/data/3306/data
启动MysqL
MysqLd --defaults-file=/home/MysqL/data/3306/my.cnf --user=MysqL
先通过unix socket修改MysqL root用户密码
MysqL -uroot -p -S /home/MysqL/data/3306/MysqL.sock
UPDATE MysqL.user SET authentication_string = PASSWORD('MysqL') WHERE USER LIKE '%root%';
grant all privileges on *.* to 'root'@'%' identified by 'MysqL' with grant option;
flush privileges;
验证通过tcp/ip协议登陆MysqL
MysqL -h127.0.0.1 -uroot -p -P3306
8.配置数据库配置文件
cd /usr/local/MysqL/ cp support-files/my-default.cnf /etc/my.cnf >/etc/my.cnf vi /etc/my.cnf [client] socket=/home/MysqL/MysqL.sock [MysqLd] symbolic-links=0 server_id = 120 default_storage_engine = Innodb user = MysqL port = 3306 basedir = /usr/local/mysq datadir = /home/MysqL/data tmpdir = /home/MysqL/tmp socket = /home/MysqL/MysqL.sock pid_file = /home/MysqL/MysqL.pid character_set_server = utf8 collation_server = utf8_general_ci open_files_limit = 10240 explicit_defaults_for_timestamp max_allowed_packet = 256M max_heap_table_size = 256M net_buffer_length = 8K sort_buffer_size = 2M join_buffer_size = 4M read_buffer_size = 2M read_rnd_buffer_size = 16M log_error = /home/MysqL/log/error.log log_bin = /home/MysqL/binlog/MysqL-bin binlog_cache_size = 32M max_binlog_cache_size = 2G max_binlog_size = 500M binlog_format = mixed log_output = FILE expire_logs_days = 5 slow_query_log = 1 long_query_time = 3 slow_query_log_file = /home/MysqL/log/slow-query.log innodb_buffer_pool_size = 500M innodb_log_file_size = 200M innodb_log_files_in_group = 3 innodb_lock_wait_timeout = 20 [MysqL] no_auto_rehash [MysqLd_safe] log-error=/home/MysqL/log/error.log
9 启动MysqL
MysqLd_safe --defaults-file=/home/MysqL/data/3306/my.cnf --user=MysqL &
10 调试MysqL
查看 MysqL进程 pid号
ps -ef | grep MysqLd
MysqL 23917 23221 15 10:27 pts/1 00:00:00 /usr/local/MysqL/bin/MysqLd --defaults-file=/home/MysqL/data/3306/my.cnf --basedir=/usr/local/MysqL --datadir=/home/MysqL/data/3306/data --plugin-dir=/usr/local/MysqL/lib/plugin --log-error=/home/MysqL/data/3306/log/error.log --open-files-limit=10240 --pid-file=/home/MysqL/data/3306/MysqL.pid --socket=/home/MysqL/data/3306/mysq.sock --port=3306
启动gdb
gdb --tui --pid 23917 --上面查看到的MysqLd进程号
进入gdb调试窗口,设置断点,
(gdb) b do_command Breakpoint 1 at 0x995820: file /root/work_dir/MysqL-8.0.1-dmr/sql/sql_parse.cc,line 1066. (gdb)
在 gdb调试窗口中输入c
Breakpoint 1 at 0x995820: file /root/work_dir/MysqL-8.0.1-dmr/sql/sql_parse.cc,line 1066. (gdb) c Continuing. [New Thread 0x7fb67d4f8700 (LWP 24769)] [New Thread 0x7fb67d4b7700 (LWP 24770)] [New Thread 0x7fb67d476700 (LWP 24771)]
开启另外一个shell终端,启动MysqL连接上面的MysqLd服务
[root@zagnix ~]# MysqL -uroot -pMysqL -h127.0.0.1 -P3306
MysqL: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MysqL monitor. Commands end with ; or \g.
---等待
在gdb调试窗口执行n或者s,就可以执行单步调试了。
通过si查看MysqL源码,b function_name 设置断点即可