Mysql 5.7.17 source code compilation and installation under Ubuntu 16.04

Posted by nev25 on Sat, 13 Jul 2019 02:28:04 +0200

Mysql 5.7.17 source code compilation and installation under Ubuntu 16.04

System Environment

ubuntu 16.04 64 bits
Official documentation states: http://dev.mysql.com/doc/refman/5.7/en/source-installation.html

I. System Installation Conditions

1.cmake

MySQL uses cmake cross-platform tools to pre-compile source code to set the compilation parameters of mysql.

sudo apt-get install cmake

2.bison

C/C++ Parser under Linux

sudo apt-get install bison

3.ncurses

Character Terminal Processing Library

sudo apt-get install libncurses5-dev

4. gcc

GCC is a C language compiling tool under Linux. The source code of mysql is compiled entirely by C and C++. Ubuntu is installed by default.

5. Boost 1.59.0

The Boost Library of C++ is used in mysql source code, which requires boost 1.59.0 to be installed.
Download the Boost 1.59.0 source code and extract it into / usr/local / directory:

wget -O https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
tar -zxvf boost_1_59_0.tar.gz -C /usr/local/

Download MySQL source code

Download mysql source code from github
https://github.com/mysql/mysql-server.git

3. Compiling MySQL source code

1. Add Mysql users

groupadd mysql
useradd -r -g mysql mysql

2. Create the directory of Mysql installer and the directory of data files

mkdir /usr/local/mysql
mkdir /home/MysqlData
chown -R mysql.mysql /user/local/mysql
chown -R mysql.mysql /home/MysqlData

3. Decompress Mysql 5.7 source code and compile it

tar -zxvf mysql-server-5.7.zip
cd mysql-server-5.7

Configure mysql precompiled parameters with cmake:
- DCMAKE_INSTALL_PREFIX: Installation Path
- DMYSQL_DATADIR: Data Storage Directory
- DWITH_BOOST: boost source path
- DSYSCONFDIR: my.cnf configuration file directory
- DEFAULT_CHARSET: Default character encoding for database
- DDEFAULT_COLLATION: Default sort rule
- DENABLED_LOCAL_INFILE: Allows data to be imported from this document
- DEXTRA_CHARSETS: Install all character sets
For more precompiled configuration parameters, please refer to the official documentation of mysql: http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html#cmake-general-options

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/home/MysqlData \
-DWITH_BOOST=/usr/local/boost_1_59_0 \
-DSYSCONFDIR=/etc \
-DEXTRA_CHARSETS=all

Compile and install (two commands separately):

sudo make
sudo make install

3. Install and configure MySQL

1. Initialize Mysql database

cd /usr/local/mysql
./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/MysqlData
# 5.7.6 Later versions of the initial system database script (this article uses the above approach)
./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/MysqlData
./bin/mysql_ssl_rsa_setup

Note: When the system database is initialized with the initialize parameter, a temporary password for root user is generated in the ~/.mysql_secret file and printed out in the initialization log.

2. Configuration files

cp support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf

[client]
port=3306
socket=/usr/local/mysql/mysql.sock
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/home/MysqlData
socket=/usr/local/mysql/mysql.sock
pid-file=/usr/local/mysql/mysql.pid
max_connections=500
default-storage-engine=MYISAM

3. Configuring Mysql services

Since Ubuntu does not have chkconfig command, Mysql service is added to the system service with update-rc.d command.

cp support-files/mysql.server /etc/init.d/mysql
update-rc.d mysql defaults
update-rc.d mysql start 2 3 4 5 . stop 0 1 6

4. Start Mysql Service

shell> service mysqld start       # service mysql start
shell> service mysqld stop        # Stop mysql service
shell> service mysqld restart     # service mysql restart

5. Setting database password

Add a skip-grant-tables line to my.cnf
Modify user table after secret-free login
Remove skip-grant-tables and restart Mysql

6. Configure mysql environment variables

shell> vim /etc/profile
shell> export PATH=/usr/local/mysql/bin:$PATH
shell> source /etc/profile

IV. Other matters needing attention

If the midway compilation fails, the cached files of the precompiled configuration parameters generated by cmake and the files generated by make compilation need to be deleted and recompiled.

shell> cd mysql-server-5.7
shell> rm -f CMakeCache.txt
shell> make clean

Topics: MySQL shell cmake sudo