MySQL 5.6 source compilation and installation

Posted by jcarver on Thu, 28 Nov 2019 08:03:49 +0100

Preface

This article is suitable for the scenarios where mysql needs debugging or mysql database is installed through source code on the localization platform. Although the title indicates mysql version 5.6, version 5.7 is also basically applicable, but the compilation parameters of cmake are slightly different from those of initializing the database.
The installation process in this article is relatively simple, and I hope it can be helpful for readers. Besides, I can think about it properly. In addition, since this article is the result of personal practice, it is purely for recording. If there is any mistake in this article, or any problem is found in the practice, please contact me for correction.

mysql 5.6 source compilation and installation

1. mysql source compilation needs to rely on ncurses library. Check whether libncurses devel package has been installed. If not, you can use yum for installation. Kylin Linux is compiled and installed using the source package:

wget http://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz
tar -zxvf ncurses-5.9.tar.gz 
cd ncurses-5.9/

# In general linux system, the - build parameter can be specified as x86 ʄ
# In the domestic system, hostnamectl can view the CPU architecture. If it is arm64/aarch64, you need to use the following command

./configure --with-shared --without-debug --without-ada --enable-overwrite --build=arm-gnu-linux

# Or the following command:
# ./configure --with-normal --without-debug --without-ada --enable-overwrite -build=arm

make -j4
make install

# Note: if there is an error during compilation, you may need to modify the line with "mouse" trafo in the curses.tail file to remove the comment

2. mysql is generally easy to compile with cmake, so first compile and install cmake from source:

wget https://github.com/Kitware/CMake/releases/download/v3.14.6/cmake-3.14.6.tar.gz
tar -zxvf cmake-3.14.6.tar.gz
cd cmake-3.14.6/
./configure && gmake -j4 && gmake install
(The following command checks if the installation is complete)
cmake --version

3. Source installation mysql-5.6.45.tar.gz + boost:

Because mysql 5.7 source package fails to compile on Kylin Linux, mysql 5.6 is used for installation here. MySQL source also depends on boost, so you need to download two packages, namely mysql 5.6 + boost. Boost can be downloaded from its official website. I lazy downloaded mysql-boost-5.7.27.tar.gz package of MySQL official website, which contains boost, and then copied it to mysql-5.6 decompression directory.

# ----Create mysql user (omitted)
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.45.tar.gz
tar -zxvf mysql-5.6.45.tar.gz
cp -R mysql-5.7.27/boost/ mysql-5.6.45/        # ------->Copy it from mysql-boost-5.7.27.tar.gz
   
cmake -DCMAKE_INSTALL_PREFIX=/var/lib/mysql -DMYSQL_DATADIR=/var/lib/mysql/data -DSYSCONFDIR=/etc -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
make -j8
make install
cd /var/lib/
chown mysql:mysql ./mysql -R

IV. create my.cnf configuration file

cd /var/lib/mysql
cp support-files/my-default.cnf /etc/my.cnf
chown mysql:mysql /etc/my.cnf
vi /etc/my.cnf

my.cnf references are as follows:

[mysqld]
    basedir=/var/lib/mysql
    datadir=/var/lib/mysql/data
    #bind-address=0.0.0.0
    port=3306
    socket=/tmp/mysql.sock
    innodb_file_per_table=1
    default-storage-engine=INNODB
    explicit_defaults_for_timestamp=true
    symbolic-links=0
    max_connections=1000
   
    log-error=/var/lib/mysql/mysql.log
    pid-file=/var/lib/mysql/mysql.pid

V. initialize mysql database and configuration

cd /var/lib/mysql
cp support-files/mysql.server /etc/init.d/mysql
chown mysql:mysql /etc/init.d/mysql
cp bin/* /usr/bin/
chkconfig --add mysql
chkconfig mysql on

mkdir data
chown mysql:mysql data/
./scripts/mysql_install_db --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data --defaults-file=/etc/my.cnf --random-passwords

# The initialization process of MySQL 5.7 is as follows:
# ./bin/mysqld --defaults-file='/etc/my.cnf' --initialize --user=mysql

/etc/init.d/mysql start                # Under normal circumstances, Success will occur during startup, otherwise the startup fails
# Or service mysql start

cat /root/.mysql_secret             # --->View random password (only available for version 5.6, the initial random password of version 5.7 is in the log file specified by log error)
mysql -uroot -pXdRmLO1T1pRRM7Jc        # Password needs to be changed after login
# Finally, open the firewall port, remote connection permission, etc

Topics: MySQL cmake Linux Database