In this article, I will briefly introduce how to debug the MySQL source code in Mac.

Debugging are used to analyze the deadlock problem because in the process of solving MySQL deadlock compare with, even if found the reason, was difficult to persuade their principle is the book or online blog about it, so he has been researching the MySQL source, it took some time to set up in the Clion debugging environment of the source. The whole process is actually very simple and smooth.

Download Clion

Clion is a C/C++ IDE tool owned by JetBrains, the second strongest IDE company in the universe. IntelliJ IDEA, PyCharm for Python and Goland for Go are all from this company, which is very good and powerful. Download the installation from the following address: www.jetbrains.com/clion/

MySQL > install MySQL

The source code selected here is version 5.5. The volume and compilation speed of the source code is much faster than that of 5.7. It does not make much difference to our understanding of the principle of MySQL, so 5.5 is selected here

#1. Download the decompressed source codeWget tar XZVF mysql - https://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.62.tar.gz - 5.5.62. Tar. Gz
#2. Generate a directoryMkdir -p build_out/data
#3. The compilation
cmake . -DWITH_DEBUG=1 \
-DCMAKE_INSTALL_PREFIX=build_out \
-DMYSQL_DATADIR=build_out/data
make && make install

#4. Initialize the mysql database
cd build_out
scripts/mysql_install_db
Copy the code

Clion configuration

1. Configure Cmake as shown in the following figure

--defaults-file=/path/to/my.cnf

[mysqld]  
log-error=log.err datadir=data pid-file=user.pid skip-grant-tables innodb_file_per_table=1 port=33060 transaction_isolation  = READ-COMMITTED [client]The default character set for client source data
default-character-set = utf8mb4
[mysqld]
# Server default character set
character-set-server=utf8mb4
The connection layer default character set
collation-server=utf8mb4_unicode_ci
[mysql]
# Database default character set
default-character-set = utf8mb4
Copy the code

Click the Debug button to debug

Note that mysqld is not in alphabetical order.

MySQL > connect to port 33060; MySQL > connect to port 33060

Cion is a very convenient breakpoint step and view variable values. For example, we can set a breakpoint in the do_command function of SQL_parse. cc and execute a SQL statement to see the step here