MySQL5.7 uses Clion to build a debugging environment under ubuntu

surroundings

  1. Ubuntu20.04
  2. CLion 2020.2.4
  3. 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


CMakeOption description: MySQL 5.7 Reference Manual

If a similar process occurs in the make Werror=xxxerrors, it can be resolved with the following scenario.

Solution : CMakeLists.txtadd 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 --initializewill be root@localhostgenerated for the user, and the user password --initialize-insecurewill be set root@localhostto 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

  1. Open the code directory with Clion

  2. Set the CMakeparameters. Click on the Filemenu bar, Settings | Build, Execution, Deployment | CMakeand CMake optionsenter cmakethe parameters when executing the command above in the input box .

Insert picture description here

  1. Run/debug MySQL. Click on Runthe menu bar Edit Configurationson the left CMake Applicationshows the MySQLrespective programs, such mysqldas MySQL Server, mysqlas MySQL CLientmay be the corresponding, Program argumentsconfigure various parameters.

I don’t have anything here, I found mysqld and started running

Insert picture description here

reference

  1. https://juejin.im/post/6855129007692873736
  2. https://blog.csdn.net/weixin_38258767/article/details/103756366
  3. https://www.jianshu.com/p/fd9beb91ad66

Guess you like

Origin blog.csdn.net/Fei20140908/article/details/109773078