Compile and install MySQL 8.0 on linux platform

Master MySQL installation from the root, and so on. Installing other c/c + + software through source code on linux platform is similar. ​

one   Installation mode

The installation package of linux is divided into RPM package, binary package and source package.

Different installation methods have their own advantages and disadvantages. Compare the three

 

RPM

Binary

Source code

advantage

Simple installation, suitable for beginners

Simple installation; Good flexibility; Multiple versions of MySQL software can be installed on a single server

Independent of the platform, it can be customized and compiled on demand, which is the most flexible; Best performance; Multiple versions of MySQL software can be installed on a single server

shortcoming

The client and server need to be downloaded separately; The installation path is not flexible, and the default path cannot be modified. One server can only install one version of MySQL software

It has been compiled, and its performance is not as good as that of the source code; Unable to customize compilation parameters flexibly

The installation process is complex; Long compilation time

File layout

/usr/bin (client programs and scripts)

/usr/sbin (mysqld server)

/var/lib/mysql (log file and database)

/usr/share/man (Linux documentation page)

/usr/include/mysql (including (header) file)

/usr/lib/mysql (library file)

/usr/share/mysql (error message and character set file)

bin (client programs, mysqld servers, and utilities)

docs (documents)

man (Linux documentation page)

Include (include (header) file)

lib (library file)

share (error message and dictionary, SQL file for installing database)

Support files

bin (client programs, mysqld servers, and utilities)

docs (documents)

man (Linux documentation page)

Include (include (header) file)

lib (library file)

share (error message and dictionary, SQL file for installing database)

Support files

The essential difference between binary and source code is that there are many source code installations: the process of compiling parameter configuration, compiling and installing source code programs into binary, but these three steps are the most time-consuming.

two   Reasons for choosing source installation

The reason is very simple: it has nothing to do with the platform. It can be customized and compiled on demand, which is the most flexible; Best performance; You can install to the directory you want to install, and support multiple versions of MySQL on a single server.

The binary installation package directly downloaded from the official website is the default compilation parameters configured according to the general situation. Some default compilation configurations may not be what you want. At this time, you should customize the compilation parameters as needed in the compilation stage to make binary MySQL installation packages that fully meet your own requirements. For example, only utf8mb4 encoding is supported for compilation.

2.1.   How to choose the installation method

Users do not want to install the simplest but not flexible RPM package, nor do they want to install complex and time-consuming source packages. They choose binary installation.
The performance requirements of the database are higher. I hope to customize the compilation parameter options more flexibly and choose the source code installation.

three   setup script

Installation environment for demonstration process:

Memory: 2 G
 Disk: 50 G
 System: CentOS 7.9
Compilation environment:gcc-10.2.0,cmake-3.21.3
Database version: mysql-8.0.27

3.1.   Environment preparation before MySQL installation

Minimum hardware requirements: 2G memory and 40G disk

This is very important!!! At first, I only gave the virtual machine 20G disk, but less than half of the compiled disk was full.

3.1.1. Install some dependencies

yum install -y gcc gcc-c++ ncurses-devel openssl openssl-devel bison bzip2

On Solaris Express, you also need to install dependencies: m4

3.1.2. Installing gcc 10.2.0

1.Download:wget -P /home https://mirrors.aliyun.com/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.gz
2.Decompression:cd /home && tar -xzvf /home/gcc-10.2.0.tar.gz
3.Configure dependencies:cd /home/gcc-10.2.0 && ./contrib/download_prerequisites

If error: Cannot download gmp-6.1.0.tar.bz2 from ftp://gcc.gnu.org/pub/gcc/infrastructure/ error

wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2

If an error is reported and other files cannot be downloaded, go to https://gcc.gnu.org/pub/gcc/infrastructure/ Download the corresponding file and copy it to / home/gcc-10.2.0.

4.Create installation folder:mkdir /usr/lib/gcc/x86_64-redhat-linux/10.2.0
5.Create compilation folder:mkdir /home/gcc-build-10.2.0
          cd /home/gcc-build-10.2.0
6.Configure installation files:../gcc-10.2.0/configure --prefix=/usr/lib/gcc/x86_64-redhat-linux/10.2.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib
7.Compilation and installation:make && make install

Come back in two hours to see if it's installed

8. Back up the original gcc

mv /usr/bin/gcc /usr/bin/gcc-4.8.5
mv /usr/bin/g++ /usr/bin/g++-4.8.5

9. Link new gcc

alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8.5 88 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8.5
alternatives --install /usr/bin/gcc gcc /usr/lib/gcc/x86_64-redhat-linux/10.2.0/bin/x86_64-pc-linux-gnu-gcc 99 --slave /usr/bin/g++ g++ /usr/lib/gcc/x86_64-redhat-linux/10.2.0/bin/x86_64-pc-linux-gnu-g++

alternatives --config gcc
Type the option number:2

View gcc version

gcc -v

10. Replace library link

rm -f /usr/lib64/libstdc++.so.6
ln -s /usr/lib/gcc/x86_64-redhat-linux/10.2.0/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6

These errors may occur when using libstdc++.so.6 library links are not replaced

/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found
/lib64/libstdc++.so.6: version `GLIBCXX_3.4.22' not found

View which libraries are currently included

strings /usr/lib64/libstdc++.so.6 | grep GLIBC

  3.1.3. Installation cmake-3.21.3

see linux Digits: getconf LONG_BIT
 download cmake:    https://cmake.org/download/
Decompression: tar zxvf cmake-3.21.3.tar.gz
 connect: cd cmake-3.21.3
Boot: ./bootstrap
 compile: gmake
Installation: make install
Easy to add soft connection cmake Use of:ln -s /home/software/cmake-3.21.3/bin/cmake /usr/bin/cmake
 see cmake edition: cmake --version

3.2. Formal installation of MySQL

1. Download the MySQL source package containing the Boost C + + library
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.27.tar.gz
2. Create new users and groups
groupadd mysql && useradd -g mysql mysql
3. Upload to the mysql user directory and unzip it
tar -zxvf mysql-boost-8.0.27.tar.gz && cd mysql-8.0.27
4. Compile the source code parameter configuration with cmake tool
cmake . -DCMAKE_INSTALL_PREFIX=/home/mysql/mysql-install \
-DMYSQL_DATADIR=/home/mysql/mysql-data \
-DWITH_DEBUG=1 \
-DWITH_BOOST=/home/mysql/mysql-8.0.27/boost \
-DCMAKE_C_COMPILER=/usr/bin/gcc \
-DCMAKE_CXX_COMPILER=/usr/bin/g++ \
-DFORCE_INSOURCE_BUILD=1
For more detailed configuration, please refer to the official document: https://dev.mysql.com/doc/refman/8.0/en/source-configuration-options.html#option_cmake_with_boost

5. Compilation and installation

compile:make
Installation:make install
Compilation error:
      make[2]: *** [CMakeFiles/abi_check] error 1
      make[1]: *** [CMakeFiles/abi_check.dir/all] error 2
 The unit test reports an error, but it does not affect the compilation
 Solution: gtest_disable_pthreads is set to ON
It takes two hours to compile and install

6. Edit the configuration file: vi /etc/my.cnf

############### Client configuration ###############
[client]
port   = 3306
socket = /home/mysql/mysql-data/mysql.sock

############### Server configuration ###############
[mysqld]
port = 3306
autocommit     = ON
character-set-server = utf8mb4
collation-server     = utf8mb4_general_ci
basedir        = /home/mysql/mysql-install
datadir        = /home/mysql/mysql-data
tmpdir         = /home/mysql/mysql-data/tmp
socket         = /home/mysql/mysql-data/mysql.sock
pid-file       = /home/mysql/mysql-data/mysql.pid
log-error      = /home/mysql/mysql-data/log/error.log
#mysql8.0 please configure it with forced lowercase before initialization, otherwise an error will be reported in the subsequent configuration
lower_case_table_names = 1

[mysql]
#Turn off the auto complete sql command function
no-auto-rehash

  7. Modify directory owner and permission

Data directory
chown -R mysql:mysql /home/mysql/mysql-data
chmod -R 750 /home/mysql/mysql-data
 Installation directory
chown -R mysql:mysql /home/mysql/mysql-install
chmod -R 750 /home/mysql/mysql-install

8. Initialize the database

bin/mysqld --initialize --user=mysql

Remember to save the initialization password after initializing the database:

password is generated for root@localhost: 0%HS>=+x/Ttf
9. Start MySQL service

bin/mysqld_safe --user=mysql &
or bin/mysqld --user=mysql &

10. Reset login password

Login with initialization password:​​mysql -u root -p
Change Password:​alter user 'root'@'localhost' identified by 'root';

mysql cannot be used normally without resetting

11. Subsequent configuration (easy to manage and use mysql)
Add soft connection

ln -s /home/mysql/mysql-install/support-files/mysql.server /etc/init.d/mysql
ln -s /home/mysql/mysql-install/bin/mysql /usr/bin/mysql

It is more convenient to use the official script (mysql.server) to manage MySQL services

It is more convenient to use the official client tool (MySQL) to connect to MySQL services

MySQL service management

Restart service
service mysql restart
 Open service
service mysql start
 Out of Service
service mysql stop
 View status
service mysql status
 Force reload
service mysql force-reload

View service: netstat -anp|grep 3306

 

reference resources:

Official documents: https://dev.mysql.com/doc/refman/8.0/en/source-installation.html

Book: MySQL: database development, optimization, management and maintenance (3rd Edition)

Original is not easy, please indicate the source!!!

  Get the PDF download link of relevant Secretary > please pay attention to the official account. 👇, Send: 135810

Keywords: Database MySQL

Added by Zoran_Dimov on Tue, 09 Nov 2021 06:14:20 +0200