surroundings
- Ubuntu20.04
- CLion 2020.2.4
- MySQL5.7 source code
Download the code and show your own magic, direct git clone will be slower
I use this oil monkey script to download a single version directly, without git related information.
Installation dependencies
Contains various dependencies required for compilation, some of which are already available in the ubuntu system
sudo apt install cmake make gcc g++ openssl libssl-dev libncurses5-dev bison
Compile and build
First, you need to try to build in the shell to see if there is any problem, and then go to Clion if there is no problem
# 进入源码目录
cd mysql-server
# 创建构建文件的目录及数据目录 以及boost目录
mkdir -p /home/xfchen/mysql/build/ /home/xfchen/mysql/build/data /home/xfchen/mysql/boost
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_PREFIX=/home/xfchen/mysql/build \
-DMYSQL_DATADIR=/home/xfchen/mysql/build/data \
-DSYSCONFDIR=/home/xfchen/mysql/build \
-DMYSQL_UNIX_ADDR=/home/xfchen/mysql/build/data/mysql.sock \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/home/xfchen/mysql/boost
# 构建
make -j 8
# 安装MySQL
make install -j 8
CMake
Option description: MySQL 5.7 Reference Manual
If a similar process occurs in the make Werror=xxx
errors, it can be resolved with the following scenario.
Solution : CMakeLists.txt
add in the fileadd_definitions(-w)
Configure and start SQL
Use the following command to initialize the database. The difference between the two parameters is that a random password --initialize
will be root@localhost
generated for the user, and the user password --initialize-insecure
will be set root@localhost
to be empty:
# 为了简单,搞成无密码的
bin/mysqld --initialize-insecure
Files needed to create an encrypted connection:
# 这一步是否必要未知,或许不需要
bin/mysql_ssl_rsa_setup
Start Mysql-server
bin/mysqld
Do not close the terminal after startup, open another terminal to start the client
Start Mysql-client
bin/mysql -uroot
Then you can create tables and the like normally.
Close mysql
Use the ps
+ kill -9 <pid>
command or close the terminal directly
Use clion to debug code
No problem with the above, you can try it on Clion
-
Open the code directory with Clion
-
Set the
CMake
parameters. Click on theFile
menu bar,Settings | Build, Execution, Deployment | CMake
andCMake options
entercmake
the parameters when executing the command above in the input box .
- Run/debug
MySQL
. Click onRun
the menu barEdit Configurations
on the leftCMake Application
shows theMySQL
respective programs, suchmysqld
asMySQL Server
,mysql
asMySQL CLient
may be the corresponding,Program arguments
configure various parameters.
I don’t have anything here, I found mysqld and started running
reference
- https://juejin.im/post/6855129007692873736
- https://blog.csdn.net/weixin_38258767/article/details/103756366
- https://www.jianshu.com/p/fd9beb91ad66