VsCode debugging MySQL source code

1. Start MySQL

2. Check the MySQL process number

[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. Use VsCode to open the MySQL source code

4. Configure the launch.json file with the following content:

{
    // 使用 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. Click the Debug Run button

6. Click Debug mysqld

7. Enter the MySQL process number of the above query and press Enter

8. Enter the MySQL debugging environment

9. Manually set breakpoints in VsCode

10. Execute SQL commands in the terminal to debug 

Guess you like

Origin blog.csdn.net/weixin_47156401/article/details/134654865