Yesterday built MySQL5.5 source debug environment, while the iron is hot, build MySQL5.7 environment, mainly marked some different parts with 5.5 build. The following analysis principle is studied on the basis of 5.7.
If you have any questions not covered in this article, please leave a message
The environment configuration is as follows:
MacOS Mojave version 10.14.6 Clion 2020.1 MySQL Version: 5.7.35Copy the code
1 Compile and install the MySQL source code
1.1 download the source code
The code address: cdn.mysql.com//Downloads/…
1.2 unzip
The tar ZXVF mysql - 5.7.35. Tar. GzCopy the code
1.3 Jump to code path and create build path
CD mysql-5.7.35 mkdir -p build_out/dataCopy the code
1.4 build
cmake . -DWITH_DEBUG=1 -DWITH_BOOST=/Users/xxx/cppProject/boost -DCMAKE_INSTALL_PREFIX=build_out -DMYSQL_DATADIR=build_out/data
Copy the code
The newline symbol is removed because \ is not recognized when Clion configudes the cmake argument.
Then compile.
make -j 24 && make install
Copy the code
The -j 24 here starts compiling for 24 threads.
1.4.1 Compilation problem: Boost is missing
If boost is not available, install it first by referring to the debug environment of the MySQL5.5 source code.
1.4.2 Compilation Problem: The OpenSSL version is too early
If the SSL version is low, you can refer to the debug environment of the MySQL5.5 source code to upgrade SSL first.
1.5 Initializing the Database
5.7 It is not initialized in this way, so this step is not needed and is initialized later in the mysqld parameter parameter.
2 configuration CLion
2.1 Creating a Cmake project
2.2 Find the mysql-5.7.35 folder and import it
【Open Existing Project】
Choose hereopen Existing Project
。
2.4 Configuring Cmake Parameters
Fill in the cmake we did in the build to cmake options: [note that WITH_BOOST should be changed to your own path address]
cmake . -DWITH_DEBUG=1 -DWITH_BOOST=/Users/xxx/cppProject/boost -DCMAKE_INSTALL_PREFIX=build_out -DMYSQL_DATADIR=build_out/data
Copy the code
Then select Apply and OK.
After CMake compiles, select mysqld.
2.5 Setting mysqld Parameters
Enter from this place below:
2.5.1 initialization
Configure –initialize-insecure and run debug.
An error was encountered:
–initialize — insecure –initialize — insecure –defaults-file –defaults-file –initialize –initialize — insecure
[ERROR] --initialize specified but the data directory has files in it. Aborting.
Copy the code
This is because I did it before adding –initialize-insecure, so I have files in the build_out/data directory. Delete the data directory and create a new one. Run debug again.
The initialization succeeds.
Increased my 2.5.2 CNF
Add the –defaults-file argument to specify where the configuration reads
- defaults - file = / Users/XXX/cppProject/mysql_source/mysql - 5.7.35 / build_out/my CNFCopy the code
The configuration of my.cnf is as follows:
[mysqld] log - error = the err datadir = / Users/XXX/cppProject mysql_source/mysql - 5.7.35 / build_out/data pid - file = user. Pid Skip-grant-tables innodb_file_per_table=1 port=33061 transaction_ISOLATION = read-committed ## lc-messages-dir This is the compiled path. The rules for adding paths are described below. Lc - messages - dir = / Users/XXX/cppProject mysql_source/mysql - 5.7.35 / build_out/share / [client] default - character - set = utf8mb4 [mysqld] character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci [mysql] default-character-set = utf8mb4Copy the code
Lc-messages-dir add rules refer to the debug environment for the MySQL5.5 source code in the previous article.
3 Startup and debugging
3.1 Starting mysqld in debug mode
The first error is reported as follows:
Warning: world-writable config file 'XXX /my.cnf' is ignoredCopy the code
The reason for this warning is that I have set the permission of 777 to the my.cnf file. MySQL thinks that anyone can change the permission, so it is not safe, so I need to manually lower the permission.
chmod 644 my.cnf
Copy the code
Debug again, the following image appears, indicating that it is started:
Let’s look at local ports:
lsof -i:33061
Copy the code
Port is up and running, good~
3.2 Using the local MySQL client to Connect
Port is 33061
The error –
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Users/xxx/cppProject/mysql-data/mysql.sock'
Copy the code
So let’s modify my.cnf and add sock path.
We did not set a password for root at initialization, so we can connect with a blank password.
Then debug again and find that sock file has been generated.
Specify sock location to connect locally again:
bin/mysql -u root -h localhost -P 33061 -S {your_mysql_sock_path}/mysql.sock
Copy the code
Success:
3.3 Interruption points and debugging
For example, if we put a breakpoint in do_command, when we execute show databases, it will stop there.