1. 启动 MySQL
2. 查看 MySQL 进程号
[root@ ~]# ps -ef | grep mysqld
root 21479 1 0 Nov01 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysqld.pid
root 26622 21479 0 Nov03 ? 03:03:35 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=root --log-error=/usr/local/mysql/data/mysqld.log --pid-file=/usr/local/mysql/data/mysqld.pid --socket=/usr/local/mysql/data/mysql.sock --port=3306
root 28442 28363 0 10:35 pts/3 00:00:00 grep --color=auto mysqld
3. 使用 VsCode 打开 MySQL 源码
4. 配置 launch.json 文件,内容如下:
{// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387"configurations": [{//"preLaunchTask": "initialize","name": "Debug mysqld","type": "cppdbg",//"request": "launch","request": "attach",//在此处直接添加进程号即可,或者直接点击调试按钮在提示窗口输入进程号"pid": "21180", // "program": "${workspaceFolder}/bld/bin/mysqld","program": "/usr/local/mysql/bin/mysqld","args": ["--defaults-file=/etc/my.cnf", "--debug=d,info:F:L","--user=mysql"],"cwd": "${workspaceFolder}"}]
}
5. 点击调试运行按钮
6. 点击 Debug mysqld
7. 输入上述查询的 MySQL 进程号,回车
8. 进入 MySQL 调试环境
9. 在 VsCode 中手动设置断点
10. 在终端执行 SQL 命令,即可调试