Install MySQL 8.x from source code under CentOS7

I will choose to install MySQL from the source code. I must have a certain understanding of MySQL and other installation methods. I won’t go into too much surrounding information here, just start.

Compiling MySQL consumes more memory. If the machine's memory is small, an out-of-memory exception may occur during compilation. If the swap partition is not set, you can set the swap partition to solve it, otherwise you can only expand the memory:

[ root@txy-server ~]# dd if=/dev/zero of=/swapfile bs=1k count=2048000[root@txy-server ~]# mkswap /swapfile
[ root@txy-server ~]# swapon /swapfile

1、 Install dependencies required for compilation###

**1.1、**Use the yum command to install the packages and tools that the compilation depends on:

[ root@txy-server ~]# yum install -y cmake3 git gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel bzip2 openssl-devel libtirpc-devel.x86_64

Since the gcc version requirement for MySQL is 5.3 or higher, we need to upgrade the gcc version first, because the latest version of yum is only 4.8.5.

There are two main ways to upgrade the gcc version, one is to download the source package to compile and install, the other is to use yum to install the devtoolset package, the current gcc version in the devtoolset package is 5.3.1.

The source code installation method is more flexible and you can choose any version, but it is very time-consuming. Both methods will be introduced here, you can choose according to the situation.

**1.1.1、**Use yum to install the devtoolset package, the command is as follows:

[ root@txy-server ~]# yum install -y centos-release-scl scl-utils-build
[ root@txy-server ~]# yum install -y devtoolset-4-gcc.x86_64 devtoolset-4-gcc-c++.x86_64 devtoolset-4-gcc-gdb-plugin.x86_64

**1.1.2、**Create a software link and overwrite the gcc-related commands under /usr/bin, because when compiling MySQL, it will find gcc-related commands in the /usr/bin directory by default:

[ root@txy-server ~]# ln -sf /opt/rh/devtoolset-4/root/usr/bin/* /usr/bin/

**1.1.3、**Finally, verify that the version of commands such as gcc, cc, c++, etc. is 5.3.1:

[ root@txy-server ~]# gcc -v
...
gcc version 5.3.120160406(Red Hat 5.3.1-6)(GCC)[root@txy-server ~]# cc -v
...
gcc version 5.3.120160406(Red Hat 5.3.1-6)(GCC)[root@txy-server ~]# c++-v
...
gcc version 5.3.120160406(Red Hat 5.3.1-6)(GCC)

**1.2.1、**The following is the source installation method, first download the GCC source installation package and unzip it:

[ root@txy-server ~]# cd /usr/local/src
[ root@txy-server /usr/local/src]# wget http://ftp.gnu.org/gnu/gcc/gcc-9.1.0/gcc-9.1.0.tar.gz
[ root@txy-server /usr/local/src]# tar -xzvf gcc-9.1.0.tar.gz

**1.2.2、**Enter the decompressed directory and run the download_prerequisites script, which will automatically download the dependent files and libraries needed for compilation:

[ root@txy-server /usr/local/src]# cd gcc-9.1.0[root@txy-server /usr/local/src/gcc-9.1.0]# ./contrib/download_prerequisites

**1.2.3、**Create an output directory and place all intermediate files in this directory:

[ root@txy-server /usr/local/src/gcc-9.1.0]# mkdir gcc-build-9.1.0

**1.2.4、**Enter the newly created directory and complete the compilation configuration:

[ root@txy-server /usr/local/src/gcc-9.1.0]# cd gcc-build-9.1.0[root@txy-server /usr/local/src/gcc-9.1.0/gcc-build-9.1.0]# ../configure -enable-checking=release -enable-languages=c,c++-disable-multilib

Parameter Description:

**1.2.5、**Then you can compile and install:

[ root@txy-server /usr/local/src/gcc-9.1.0/gcc-build-9.1.0]# make && make install

**1.2.6、**Create a software link and overwrite the gcc-related commands under /usr/bin, because when compiling MySQL, it will find gcc-related commands in the /usr/bin directory by default:

[ root@txy-server ~]# ln -sf /usr/local/bin/* /usr/bin/

**1.2.7、**Finally, verify whether the gcc version is 9.1.0, the following means the installation is successful:

[ root@txy-server ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:../configure -enable-checking=release -enable-languages=c,c++-disable-multilib
Thread model: posix
gcc version 9.1.0(GCC)[root@txy-server ~]#

2、 Download the MySQL source code package, unzip, compile and install###

**2.1、**Enter the download address of MySQL official website:

https://dev.mysql.com/downloads/mysql/

**2.2、**Copy the download link of the source package:

**2.3、**Download and unzip the source package on Linux:

[ root@txy-server ~]# cd /usr/local/src
[ root@txy-server /usr/local/src]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.18.tar.gz[root@txy-server /usr/local/src]# tar -zxvf mysql-boost-8.0.18.tar.gz

**2.4、**Enter the decompressed directory and follow the steps below to complete the compilation and installation:

# Create a data file storage directory
[ root@txy-server /usr/local/src]# mkdir -p /data/mysql
[ root@txy-server /usr/local/src]# cd mysql-8.0.18/
# Create a new directory to store the intermediate files generated by the compilation. Because it is not allowed to compile in the source directory
[ root@txy-server /usr/local/src/mysql-8.0.18]# mkdir builder
[ root@txy-server /usr/local/src/mysql-8.0.18]# cd builder/[root@txy-server /usr/local/src/mysql-8.0.18/builder]# cmake3 ../-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1-DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_TCP_PORT=3306-DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_DEBUG=0-DMYSQL_MAINTAINER_MODE=0-DWITH_SYSTEMD=1-DDOWNLOAD_BOOST=1-DWITH_BOOST=../boost
[ root@txy-server /usr/local/src/mysql-8.0.18/builder]# make && make install

Description of the parameters used by cmake3 command:

For the parameters supported by cmake3, you can check the official website document:

https://dev.mysql.com/doc/refman/8.0/en/source-configuration-options.html

**2.5、**After compiling and installing, create a mysql user and change the owner of the corresponding directory:

[ root@txy-server ~]# groupadd mysql
[ root@txy-server ~]# useradd -M -g mysql -s /sbin/nologin mysql
[ root@txy-server ~]# chown -R mysql:mysql /usr/local/mysql/[root@txy-server ~]# chown -R mysql:mysql /data/mysql/

**2.6、**Edit the configuration file:

[ root@txy-server ~]# vim /etc/my.cnf
[ mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock

[ mysqld_safe]
log-error=/var/log/mysqld/mysqld.log
pid-file=/var/run/mysqld/mysql.pid

**2.7、**Create the directory where the log file is stored and the directory where the pid file is stored, and grant the permissions to the mysql user:

[ root@txy-server ~]# mkdir -p /var/log/mysqld /var/run/mysqld
[ root@txy-server ~]# chown -R mysql:mysql /var/log/mysqld
[ root@txy-server ~]# chown -R mysql:mysql /var/run/mysqld

**2.8、**Configure environment variables to facilitate the use of MySQL commands:

[ root@txy-server ~]# vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
[ root@txy-server ~]# source /etc/profile
[ root@txy-server ~]# mysql --version  #Verify that the configuration is successful
mysql  Ver 8.0.18for Linux on x86_64(Source distribution)[root@txy-server ~]#

**2.9、**Execute the following command to initialize the database:

[ root@txy-server ~]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql/--datadir=/data/mysql

After the initialization is successful, the default password of the root account will be generated, as shown in the following figure:

Copy and save the password, because you will need to log in to MySQL to modify the password later

**2.10、**Copy the startup file generated by MySQL to the /usr/lib/systemd/system/ directory:

[ root@txy-server ~]# cp /usr/local/src/mysql-8.0.18/builder/scripts/mysqld.service /usr/lib/systemd/system/[root@txy-server ~]# chown 775/usr/lib/systemd/system/mysqld.service

**2.11、**Use the systemctl command to start the MySQL service:

[ root@txy-server ~]# systemctl start mysqld

**2.12、**Check whether port 3306 has been monitored normally:

[ root@txy-server ~]# netstat -lntp |grep 3306
tcp6       00:::33060:::*                    LISTEN      27363/mysqld
tcp6       00:::3306:::*                    LISTEN      27363/mysqld
[ root@txy-server ~]#

**2.13、**Use the default password to log in to MySQL, reset the password and open remote login:

[ root@txy-server ~]# mysql -uroot -pmXyfy/g8\)aus
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';  #reset Password
mysql> use mysql;
mysql> update user set host ='%' where user='root';  #Open remote login
mysql> FLUSH PRIVILEGES;  #Refresh modification

**2.14、**Use a visualization tool to connect remotely and test whether you can access MySQL normally:

end

Recommended Posts

Install MySQL 8.x from source code under CentOS7
Install mysql5.7 under CentOS7
CentOS7.5 source code compile and install mysql5.7.29
Install mysql under Centos 7
Install mysql5.1 under CentOS6.5
CentOS7.4 source code compile and install MySQL8.0
How to install openssh from centos 7 source code
Install MySQL under Linux (CentOS 7)
Centos6 install mysql 5.7.x series
Compile and install OpenJDK8 from source code under Ubuntu 18.04.1
Compile FFMPEG source code under CentOS7
CentOS7.2 install Mysql5.7.13
CentOS7 install MySQL
CentOS install mysql
CentOS7 install mysql
CentOS 7 install MySQL 5.6
CentOS8 install MySQL8.0
CentOS7 install mysql8
CentOS7 install MySQL8
centos 7.5 install mysql5.7.17
Install mysql8.0.13 version under Linux CentOS7 system
CentOS6.5 offline install MySQL5.6.26
Install MySQL5.7 in centos7
Install MySQL 5.7 under CentOS 7 for middle class children!
Install mysql under Ubuntu 16.04
Install ActiveMQ under Centos7
Install PostgreSQL12 under CentOS7
Install CentOS under VMware
CentOS 7.2 Yum install MySQL 5.6
Centos7 install Mysql8 tutorial
CentOS 6.X install VirtualBox-5.1
Centos7 install mongodb 4.x
Centos manually install mysql8
Centos7 install Mysql database
Install Jenkins under Centos 7
Install MariaDB under MariaDB Centos7
Install MySQL under Ubuntu
Install mysql online on centos
centos install mysql through yum
Install ElasticSearch 7.x on CentOS 7
Install MySQL 8.0.16 on Linux Centos
Install Oracle11gR2 database under CentOS6.9
CentOS 6.x installation mysql5.7 record
Install Java JDK8 under CentOS6
Centos compile JDK8 source code
Install MongoDB database under CentOS7
CentOS 6.8 under linux install mongodb
CentOS8 install MySQL8 (pro test)
Install Mesos tutorial under CentOS7
CentOS7 yum install and start mysql
Install and configure keepalived under CentOS 5.9
CentOS Yum compile and install MySQL 5.6
Compile and install LAMP under Centos 5.2
[Introduction to redis] Install redis under Centos
CentOS 7 install Nginx, PHP, MySQL packages
CentOS 6.x compile and install Nginx
Install MySQL on Linux CentOS7 (Windows)
CentOS7 yum install and start mysql
Install MySQL under Ubuntu 18.04 (graphic tutorial)
Install Harbor mirror warehouse under CentOS
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple