Compiling and Installing MySQL
This section describes how to compile and install MySQL using the source code. MySQL 8.0.25 is used as an example. You can refer to this section when compiling and installing MySQL of other versions.
1
|
rm -rf /home/mysql-8.0.25 |
- Download the MySQL source package.
- Download the MySQL source package (including Boost Headers).
URL: https://downloads.mysql.com/archives/community/

If the server is connected to the Internet, run the wget command to download the MySQL source code.
1 2
cd /home wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-8.0.25.tar.gz --no-check-certificate
- Upload mysql-boost-8.0.25.tar.gz to the /home directory on the server and decompress it.
1 2
cd /home tar -zxvf mysql-boost-8.0.25.tar.gz
- Download the MySQL source package (including Boost Headers).
- Go to the /home/mysql-8.0.25 source code directory and create a build directory.
1 2
cd /home/mysql-8.0.25 mkdir build
- Go to the build directory and configure MySQL.
1 2
cd build cmake .. -DBUILD_CONFIG=mysql_release -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DWITH_BOOST=/home/mysql-8.0.25/boost/boost_1_73_0
Set the paths in the preceding commands based on your requirements. Table 1 describes the key parameters.
Table 1 Parameter description Parameter
Description
DBUILD_CONFIG
Specifies the compile parameters to be used. The value mysql_release indicates that the compile parameters in the official MySQL release are used.
DCMAKE_INSTALL_PREFIX
Specifies the software installation directory. In this example, the installation directory is /usr/local/mysql.
The installation directories in the documents are for reference only. Replace them with the actual directories to match your installation.
DMYSQL_DATADIR
Specifies the directory for storing data files during database creation. In this example, the data directory is /data/mysql/data.
DWITH_BOOST
Specifies the directory of the boost_1_73_0 folder after the MySQL source package is decompressed. For example, if the package is decompressed in the /home directory, the directory for the folder is /home/mysql-8.0.25/boost/boost_1_73_0.
- Compile and install MySQL.
1 2
make -j 96 make -j 96 install
In the command, -j 96 can make full use of the multi-core feature of the CPUs to accelerate the compilation. The number following -j indicates the number of CPU cores. You can run the cat /proc/cpuinfo | grep processor | wc -l command to query the number of CPU cores. The value specified must be less than or equal to the actual number of CPU cores.
- Check the MySQL installation directory.
1ls /usr/local/mysql/Expected result:
bin docs include lib LICENSE LICENSE.router LICENSE-test man mysqlrouter-log-rotate mysql-test README README.router README-test run share support-files var
- Check the database version.
1/usr/local/mysql/bin/mysql --versionExpected result:
/usr/local/mysql/bin/mysql Ver 8.0.25 for Linux on aarch64 (Source distribution)