MySQL series (1): CentOS7 compile and install MySQL5.7

introduction

In order to facilitate subsequent debugging and learning of the source code, first compile a Debug version of MySQL by yourself. The environment I use here is the CentOS version of WSL. If the system is not Win10 and does not have WSL, you can install CentOS with a virtual machine, or pull a CentOS image in Docker to create an instance. MySQL chooses the latest GA version in 5.7, namely 5.7.28.

download source code

My WSL is automatically logged in as root, and the user directory is /root. Download the source code from the official MySQL CDN, and decompress it to the user directory. The directory I placed here is /root/develop/mysql-5.7.28, where mysql-5.7.28 is the folder that comes with the compressed package.

wget https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
tar -xzvf mysql-boost-5.7.28.tar.gz -C ~/develop

build install

Install the dependent tools. If you don’t know which one to install at the beginning, you can not install it first. When a command is missing during execution, or a compilation error will prompt what tools are missing, then add them one by one.

yum install -y cmake gcc gcc-c++ gdb
yum install -y openssl-devel ncurses-devel
yum install -y bison

gcc/gcc-c++ is a compiler for C and C++, cmake is a build tool, gdb is a debugger, openssl-devel is a development package for TLS and SSL protocols, ncurses-devel is a development package for character terminal display, and bison is a grammar Analyzer generator.

Then you can start compiling and installing. First, create a folder output to store the files generated during the compilation process, which is convenient for management. This is also the benefit of using cmake, you can create multiple folders and build them with different parameters.

cd ~/develop/mysql-5.7.28
mkdir output
cd output
cmake .. -DWITH_DEBUG=1 \
-DWITH_UNIT_TESTS=0 \
-DWITH_BOOST=../boost/boost_1_59_0

make -j 10
make install

The WITH_DEBUG parameter sets whether the compilation mode is Debug. After configuring this parameter, the script will set CMAKE_BUILD_TYPE=Debug. The WITH_UNIT_TESTS parameter sets whether unit tests are required. The boost library provides extended functions for the C++ standard library, which is included in the source code we downloaded, and you need to use WITH_BOOST to specify the path of the boost library. Since the compilation is very slow, set 10 threads here to speed up the compilation.

If an error occurs during the cmake process, you need to delete the CMakeCache.txt file, and then run cmake again.

rm CMakeCache.txt

If you want to delete all the files generated during the compilation and installation process, you can run the following command:

xargs rm < install_manifest.txt
rm -rf ../output

When make install, the installed files will be recorded in install_manifest.txt. Check the file and you can find that they are placed under /usr/local/mysql by default, so delete the two folders /usr/local/mysql and output.

initialization

If it is initialized directly with the root user, an error will be reported if it is not allowed. So before initialization, create a mysql group and a mysql user who is not allowed to log in, and give it the permissions of our compiled mysql directory.

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
chown -R mysql:mysql /usr/local/mysql

mysqld is the core program of MySQL. After initialization with the initialize parameter, the data folder will be automatically generated, usually /usr/local/mysql/data, and the root user of MySQL will also be created with an initial password. Note that it is copied from the console. A login is required to use. mysql_ssl_rsa_setup will create SSL certificates and RSA public and private keys.

/usr/local/mysql/bin/mysqld --initialize --user=mysql
/usr/local/mysql/bin/mysql_ssl_rsa_setup

After mysqld --initialize --user=mysql is executed, the root password output by the console is as follows:

[Note] A temporary password is generated for root@localhost: haQ2Ql3gM+T1

Here haQ2Ql3gM+T1 is the password, which is a different value each time it is initialized. Next, start mysqld, connect with the mysql client, change an easy-to-remember password, and you're done.

/usr/local/mysql/bin/mysqld_safe --user=mysql &

mysqld_safe is a script file that will help us start mysqld. You can also start mysqld directly, but you need to specify more parameters. If you want to debug with gdb, you can only use mysqld.

/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql

change Password

Log in to mysql and change the password to 123456.

/usr/local/mysql/bin/mysql -u root -p
SET PASSWORD = PASSWORD('123456');

Because the purpose of compiling here is for subsequent debugging, the service is not set to start automatically.

Key words

Download source code; build and install; initialize; change password


Welcome to pay attention to the official account, it is more convenient to get push, and to communicate when encountering problems!

Technical long-distance running

Je suppose que tu aimes

Origine blog.csdn.net/CanvaChen/article/details/102790821
conseillé
Classement