MySQL之——源码编译MySQL8.x+升级gcc+升级cmake(亲测完整版)

一、概述

最近,在CentOS 6.8服务器上编译安装MySQL 8.0.18的源码,百度了许久,发现网上的安装方式没一个可用的。基本都是基于CentOS 7.x来安装MySQL8.0,并且安装过程中会出现各种问题,按照他们的文章进行安装根本解决不了问题。更重要的一点就是,很多文章的内容一模一样!!我就纳闷了,那些发表文章的人,自己真的安装并且验证过吗?还是只是一味的抄袭呢?!


确实很无语啊,对于一个技术人来说,一定要解决这个问题。于是我彻底关闭了百度,开始翻看MySQL官方文档,自己研究安装方式,总结出MySQL 8.x在各CentOS版本下的安装方式,整理成文,供大家参考。


本文的安装方式涉及到的CentOS版本不限,MySQL版本为8.x。

二、安装版本


本文以如下版本为例进行介绍。


    服务器:CentOS:6.8

    MySQL:8.0.18

    gcc:9.2.0

    cmake:3.15.2


服务器配置。


这里,我编译安装MySQL8.0.18时,使用的服务器配置如下。


CentOS 6.8,内存6G,磁盘60G。


我在内存4G,磁盘60G的情况下,编译不成功,内存不足;在内存6G,磁盘20G的情况下,编译也不成功,磁盘空间不足,所以编译安装MySQL 8.x还是需要一定的内存和磁盘空间的。


三、安装环境准备

1.安装基础依赖环境

在CentOS 6.8服务器中安装一些基础依赖环境,如下所示。

yum -y install xz wget gcc-c++ ncurses ncurses-devel cmake make perl openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype* make gcc-c++ cmake bison-devel bison perl perl-devel  perl perl-devel glibc-devel.i686 glibc-devel libaio ntpdate readline-devel zlib.x86_64 zlib-devel.x86_64 libcurl-* net-tool*  sysstat lrzsz dos2unix telnet.x86_64 nethogs iftop iotop unzip ftp.x86_64 xfs* expect vim psmisc openssh-client* libaio libaio1 libnuma bzip2  epel-release


2.修改服务器配置

修改CentOS 6.8服务器配置,如下所示

[root@binghe ~]# vim /etc/selinux/config
SELINUX=disabled


3.添加mysql用户


groupadd mysql
useradd -g mysql mysql


4.创建安装MySQL所需要的目录


mkdir -p /usr/local/mysql
mkdir -p /data/mysql/run
mkdir -p /data/mysql/data
mkdir -p /data/mysql/tmp
mkdir -p /data/mysql/conf
mkdir -p /data/mysql/log/bin_log
mkdir -p /data/mysql/log/error_log
mkdir -p /data/mysql/log/query_log
mkdir -p /data/mysql/log/general_log
mkdir -p /data/mysql/log/innodb_ts
mkdir -p /data/mysql/log/undo_space
mkdir -p /data/mysql/log/innodb_log


5.mysql用户授予目录权限


chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/mysql


四、下载并安装MySQL

1.下载安装软件包


cd /usr/local/src/
wget https://mirrors.ustc.edu.cn/gnu/gmp/gmp-6.1.2.tar.xz
wget https://mirrors.ustc.edu.cn/gnu/mpfr/mpfr-4.0.2.tar.gz
wget https://mirrors.ustc.edu.cn/gnu/mpc/mpc-1.1.0.tar.gz
wget https://mirrors.ustc.edu.cn/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz
wget https://github.com/Kitware/CMake/releases/download/v3.15.2/cmake-3.15.2.tar.gz
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18.tar.gz

如果需要通过网页下载MySQL源码,可以在浏览器地址栏输入链接https://dev.mysql.com/downloads/mysql/ 。并按照下图方式选择MySQL源码。


MySQL之——源码编译MySQL8.x+升级gcc+升级cmake(亲测完整版)


2.升级gcc

(1)先编译安装gmp->mpfr->mpc

编译gmp


cd /usr/local/src/
xz -d gmp-6.1.2.tar.xz
tar -xvf gmp-6.1.2.tar
cd gmp-6.1.2
./configure --prefix=/usr/local/gmp-6.1.2
make -j $(nproc)
make install
  • 编译mpfr

cd /usr/local/src
tar -xvf mpfr-4.0.2.tar.gz
cd mpfr-4.0.2
./configure --prefix=/usr/local/mpfr-4.0.2 --with-gmp=/usr/local/gmp-6.1.2
make -j $(nproc)
make install
  • 编译mpc



cd /usr/local/src
tar -xvf mpc-1.1.0.tar.gz
cd mpc-1.1.0
./configure --prefix=/usr/local/mpc-1.1.0 --with-mpfr=/usr/local/mpfr-4.0.2  --with-gmp=/usr/local/gmp-6.1.2
make -j $(nproc)
make install


(2)配置mpfr

把mpfr lib 加入 ld.so.conf 不然gcc 编译报错



echo /usr/local/mpfr-4.0.2/lib  >> /etc/ld.so.conf
ldconfig


(3)配置系统环境变量




vim /etc/profile
MPC_HOME=/usr/local/mpc-1.1.0
GMP_HOME=/usr/local/gmp-6.1.2
MPFR_HOME=/usr/local/mpfr-4.0.2
LD_LIBRARY_PATH=$MPC_LIB_HOME/lib:$GMP_HOME/lib:$MPFR_HOME/lib:$LD_LIBRARY_PATH
export MPC_LIB_HOME GMP_HOME MPFR_HOME LD_LIBRARY_PATH


输入如下命令使系统环境变量生效。


source /etc/profile


(4)创建软链接

ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /lib64/libmpc.so.3
ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /lib/libmpc.so.3
ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /usr/lib64/libmpc.so.3
ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /usr/lib/libmpc.so.3
ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /usr/local/lib64/libmpc.so.3
ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /usr/local/lib/libmpc.so.3


(5)升级gcc

首先,执行如下命令安装gcc。



cd /usr/local/src/
tar -zxvf gcc-9.2.0.tar.gz
cd gcc-9.2.0
./configure --prefix=/usr/local/gcc-9.2.0 -enable-threads=posix -disable-checking -disable-multilib -enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.1.2/  --with-mpfr=/usr/local/mpfr-4.0.2/ --with-mpc=/usr/local/mpc-1.1.0/ -with-tune=generic --with-arch_32=x86-64
make -j $(nproc)
make install -j $(nproc)

接下来,备份旧gcc的可执行文件


 mv /usr/bin/gcc /usr/bin/gcc.old
 mv /usr/bin/g++ /usr/bin/g++.old
 mv /usr/bin/c++ /usr/bin/c++.old
 mv /usr/bin/cpp /usr/bin/cpp.old
 mv /usr/bin/gcov /usr/bin/gcov.old


创建最新gcc 执行文件软链

ln -sf /usr/local/gcc-9.2.0/bin/* /usr/bin/


删除gcc安装目录下的lib64 目录下的.py 文件。


rm -rf /usr/local/gcc-9.2.0/lib64/libstdc++.so.6.0.27-gdb.py

配置ld.so.conf文件。



echo /usr/local/gcc-9.2.0/lib64 >> /etc/ld.so.conf
ldconfig


复制libstdc++.so.6.0.27文件到/lib64/目录


cp /usr/local/gcc-9.2.0/lib64/libstdc++.so.6.0.27 /lib64/


创建软链 libstdc++.so.6


cd /lib64ln  -sf libstdc++.so.6.0.27 libstdc++.so.6

查看是否最新版本


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

至此,gcc升级完成。


(6)升级cmake

首先,编译安装cmake。



cd  /usr/local/src/
tar -zxvf cmake-3.15.2.tar.gz
cd cmake-3.15.2
./configure --prefix=/usr/local/cmake-3.15.2
gmake -j $(nproc)
gmake install -j $(nproc)

注意:这里使用的是gmake命令。

接下来,创建cmake 软链。


ln -sf /usr/local/cmake-3.15.2/bin/cmake /bin/cmake3

至此,cmake升级完成。


(7)编译安装MySQL



cd /usr/local/src
tar -zxvf mysql-8.0.18.tar.gz
cd mysql-8.0.18
cmake3 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/data/mysql/data -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=ON -DWITH_INNODB_MEMCACHED=ON -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DCOMPILATION_COMMENT="binghe edition" -DDOWNLOAD_BOOST=1  -DWITH_BOOST=/data/mysql/tmp -DMYSQL_UNIX_ADDR=/data/mysql/run/mysql.sock -DMYSQL_TCP_PORT=3306 -DSYSCONFDIR=/data/mysql/conf -DWITH_READLINE=1 -DFORCE_INSOURCE_BUILD=1 -DWITH_SSL=system -DWITH_ZLIB=system   -DCMAKE_CXX_COMPILER=/usr/local/gcc-9.2.0/bin/g++ -DCMAKE_C_COMPILER=/usr/local/gcc-9.2.0/bin/gcc
gmake -j $(nproc)
gmake install -j $(nproc)


编译安装完成后,查看MySQL的安装目录,如下所示。



[root@binghe ~]# cd /usr/local/mysql/
[root@binghe mysql]# ll
total 956
drwxr-xr-x  2 mysql mysql   4096 Nov 23 02:15 bin
drwxr-xr-x  2 mysql mysql   4096 Nov 23 02:15 docs
drwxr-xr-x  3 mysql mysql   4096 Nov 23 02:14 include
drwxr-xr-x  6 mysql mysql   4096 Nov 23 02:15 lib
-rw-r--r--  1 mysql mysql 408918 Sep 20 16:30 LICENSE
-rw-r--r--  1 mysql mysql 102977 Sep 20 16:30 LICENSE.router
-rw-r--r--  1 mysql mysql 408918 Sep 20 16:30 LICENSE-test
drwxr-xr-x  4 mysql mysql   4096 Nov 23 02:15 man
drwxr-xr-x 10 mysql mysql   4096 Nov 23 02:15 mysql-test
-rw-r--r--  1 mysql mysql    687 Sep 20 16:30 README
-rw-r--r--  1 mysql mysql    700 Sep 20 16:30 README.router
-rw-r--r--  1 mysql mysql    687 Sep 20 16:30 README-test
drwxrwxr-x  2 mysql mysql   4096 Nov 23 02:15 run
drwxr-xr-x 28 mysql mysql   4096 Nov 23 02:15 share
drwxr-xr-x  2 mysql mysql   4096 Nov 23 02:15 support-files
drwxr-xr-x  3 mysql mysql   4096 Nov 23 02:15 var
[root@binghe mysql]#

说明,MySQL 8.0.18编译安装成功。

五、配置M

1.配置mysql用户系统参数



[root@binghe ~]# vim /etc/security/limits.conf
mysql soft nproc 65536
mysql hard nproc 65536
mysql soft nofile 65536
mysql hard nofile 65536


2.配置系统环境变量




vim /etc/profile
MYSQL_HOME=/usr/local/mysql
MPC_HOME=/usr/local/mpc-1.1.0
GMP_HOME=/usr/local/gmp-6.1.2
MPFR_HOME=/usr/local/mpfr-4.0.2
LD_LIBRARY_PATH=$MPC_LIB_HOME/lib:$GMP_HOME/lib:$MPFR_HOME/lib:$LD_LIBRARY_PATH
PATH=$MYSQL_HOME/bin:$PATH
export MYSQL_HOME MPC_LIB_HOME GMP_HOME MPFR_HOME LD_LIBRARY_PATH PATH

输入如下命令使系统环境变量生效。



source /etc/profile

3.配置/etc/ld.so.conf文件



echo /usr/local/mysql/lib >> /etc/ld.so.conf
ldconfig


4.复制MySQL启动文件




cp mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld

5.配置MySQL开机自启动



chkconfig --level 35 mysqld on

6.配置MySQL配置文件my.cnf


在使用cmake预编译MySQL时,配置了如下参数。


-DSYSCONFDIR=/data/mysql/conf


所以,这里,我们把my.cnf文件放到/data/mysql/conf目录下,如下所示


vim /data/mysql/conf/my.cnf

my.cnf文件的内容如下


[client]
port = 3306
socket = /data/mysql/run/mysql.sock
default-character-set = utf8mb4
 
# The MySQL server
[mysqld]
port = 3306
user = mysql
socket = /data/mysql/run/mysql.sock
pid_file = /data/mysql/run/mysqld.pid
basedir = /usr/local/mysql
datadir = /data/mysql/data
tmpdir = /data/mysql/tmp
open_files_limit = 65535
explicit_defaults_for_timestamp
server_id = 1
lower_case_table_names = 1
character_set_server = utf8mb4
safe_user_create
max_connections = 3000
max_user_connections=2980
secure_file_priv=/data/mysql/tmp
 
max_connect_errors = 100000
interactive_timeout = 86400
wait_timeout = 86400
sync_binlog=100
back_log=1024
max_binlog_cache_size=2147483648
max_binlog_size=524288000
default_storage_engine = InnoDB
log_slave_updates = 1
 
#*********** Logs related settings ***********
log_bin = /data/mysql/log/bin_log/mysql-bin
binlog_format= mixed
binlog_cache_size=32m
max_binlog_cache_size=64m
max_binlog_size=512m
long_query_time = 1
log_output = FILE
log_error = /data/mysql/log/error_log/mysql-error.log
slow_query_log = 1
slow_query_log_file = /data/mysql/log/query_log/slow_statement.log
log_queries_not_using_indexes=0
log_slave_updates=ON
log_slow_admin_statements=1
general_log = 0
general_log_file = /data/mysql/log/general_log/general_statement.log
binlog_expire_logs_seconds = 1728000
relay_log = /data/mysql/log/bin_log/relay-bin
relay_log_index = /data/mysql/log/bin_log/relay-bin.index
#****** MySQL Replication New Feature*********
master_info_repository=TABLE
relay-log-info-repository=TABLE
relay-log-recovery
#*********** INNODB Specific options ***********
innodb_buffer_pool_size = 4096M
transaction_isolation=REPEATABLE-READ
innodb_buffer_pool_instances = 8
innodb_file_per_table = 1
innodb_data_home_dir = /data/mysql/log/innodb_ts
innodb_data_file_path = ibdata1:2048M:autoextend
innodb_thread_concurrency = 8
innodb_log_buffer_size = 67108864
innodb_log_file_size = 1048576000
innodb_log_files_in_group = 4
innodb_max_undo_log_size=4G
innodb_undo_directory=/data/mysql/log/undo_space/
 
 
innodb_log_group_home_dir = /data/mysql/log/innodb_log/
innodb_adaptive_flushing=ON
innodb_flush_log_at_trx_commit = 2
innodb_max_dirty_pages_pct = 60
innodb_open_files=60000
innodb_purge_threads=1
innodb_read_io_threads=4
innodb_stats_on_metadata=OFF
innodb_flush_method=O_DIRECT
[mysql]
no-auto-rehash
default-character-set=utf8mb4
net-buffer-length=64K
unbuffered
max-allowed-packet = 2G
default-character-set = utf8mb4
 
#some var for mysql8
#log_error_verbosity=3
#innodb_print_ddl_logs=1
#binlog_expire_logs_seconds=259200
#innodb_dedicate_server=0
#
#innodb_status_file=1
#innodb_status_output=0
#innodb_status_output_locks=0
 
[mysqldump]
quick
max_allowed_packet=2G
log_error=/data/mysql/log/error_log/mysql_dump_error.log
net_buffer_length=8k


六、初始化MySQL并启动MySQL

输入如下命令初始化MySQL数据。


mysqld --defaults-file=/data/mysql/conf/my.cnf --initialize --user=mysql

接下来,启动MySQL



service mysqld start


七、登录MySQL并修改密码

初始化数据时,MySQL会为root账户自动生成一个临时密码,这个临时密码保存在my.cnf文件log_error配置的文件中,我们在my.cnf中配置了如下参数。

log_error = /data/mysql/log/error_log/mysql-error.log


所以,MySQL为root账户自动生成的临时密码保存在/data/mysql/log/error_log/mysql-error.log文件中。

接下来,查看MySQL为root账户自动生成的临时密码,如下所示。

vim /data/mysql/log/error_log/mysql-error.log


在mysql-error.log文件中,找到如下一行代码。

2019-11-22T19:05:02.240204Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ujbbqC?A+38g


可以看到临时密码为:ujbbqC?A+38g

接下来,使用root账户和这个临时密码登录MySQL服务器。


[root@binghe ~]# mysql -uroot -pujbbqC?A+38g
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 binghe edition
 
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql>

此时,在MySQL命令行执行SQL语句报错,要求重置密码,如下所示。

mysql> SHOW DATABASES;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>

接下来,修改MySQL的root密码


mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '@Binghe123456';
Query OK, 0 rows affected (0.03 sec)
 
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

退出MySQL,并使用root账户和修改后的密码登录MySQL,如下所示。


mysql> exit
Bye
[root@binghe150 ~]# mysql -uroot -p@Binghe123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.18 binghe edition
 
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql>


此时,使用root账户和修改后的密码成功登录MySQL,说明root账户密码修改成功。

接下来,再次在MySQL命令行执行SQL语句,如下所示。


mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)
 
mysql> USE mysql;
Database changed
mysql>

可以看到,修改root账户密码后,再次登录MySQL,可以在命令行正确执行SQL语句。

至此,源码编译MySQL8.x+升级gcc+升级cmake完美完成。


八、遇到的问题和解决方案

编译安装gcc报错

编译安装gcc时报错,报错信息如下所示。



/usr/local/src/gcc-9.2.0/host-x86_64-pc-linux-gnu/gcc/xgcc -B/usr/local/src/gcc-9.2.0/host-x86_64-pc-linux-gnu/gcc/ -xc -nostdinc /dev/null -S -o /dev/null -fself-test=../.././gcc/testsuite/selftests
/usr/local/src/gcc-9.2.0/host-x86_64-pc-linux-gnu/gcc/cc1plus: error while loading shared libraries: libmpc.so.3: cannot open shared object file: No such file or directory
make[3]: *** [s-selftest-c++] Error 1
make[3]: *** Waiting for unfinished jobs....
/usr/local/src/gcc-9.2.0/host-x86_64-pc-linux-gnu/gcc/cc1: error while loading shared libraries: libmpc.so.3: cannot open shared object file: No such file or directory
make[3]: *** [s-selftest-c] Error 1
/usr/local/src/gcc-9.2.0/host-x86_64-pc-linux-gnu/gcc/cc1: error while loading shared libraries: libmpc.so.3: cannot open shared object file: No such file or directory
/bin/sh ../.././gcc/../move-if-change tmp-macro_list macro_list
echo timestamp > s-macro_list
rm gcc.pod
make[3]: Leaving directory `/usr/local/src/gcc-9.2.0/host-x86_64-pc-linux-gnu/gcc'
make[2]: *** [all-stage1-gcc] Error 2
make[2]: Leaving directory `/usr/local/src/gcc-9.2.0'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/usr/local/src/gcc-9.2.0'
make: *** [all] Error 2
/usr/local/src/gcc-9.2.0/host-x86_64-pc-linux-gnu/gcc/cc1: error while loading shared libraries: libgmp.so.10: cannot open shared object file: No such file or directory
/usr/local/src/gcc-9.2.0/host-x86_64-pc-linux-gnu/gcc/cc1: error while loading shared libraries: libgmp.so.10: cannot open shared object file: No such file or directory
make[3]: *** [s-selftest-c] Error 1
make[3]: *** Waiting for unfinished jobs....
/usr/local/src/gcc-9.2.0/host-x86_64-pc-linux-gnu/gcc/cc1plus: error while loading shared libraries: libgmp.so.10: cannot open shared object file: No such file or directory
/bin/sh ../.././gcc/../move-if-change tmp-macro_list macro_list
make[3]: *** [s-selftest-c++] Error 1
echo timestamp > s-macro_list
rm gcc.pod
make[3]: Leaving directory `/usr/local/src/gcc-9.2.0/host-x86_64-pc-linux-gnu/gcc'
make[2]: *** [all-stage1-gcc] Error 2
make[2]: Leaving directory `/usr/local/src/gcc-9.2.0'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/usr/local/src/gcc-9.2.0'
make: *** [all] Error 2


解决方案如下:

首先,配置系统环境变量,如下:


vim /etc/profile
 
MPC_HOME=/usr/local/mpc-1.1.0
GMP_HOME=/usr/local/gmp-6.1.2
MPFR_HOME=/usr/local/mpfr-4.0.2
LD_LIBRARY_PATH=$MPC_LIB_HOME/lib:$GMP_HOME/lib:$MPFR_HOME/lib:$LD_LIBRARY_PATH
export MPC_LIB_HOME GMP_HOME MPFR_HOME LD_LIBRARY_PATH

使系统环境变量生效,如下所示


source /etc/profile

接下来,创建系统软链接,如下所示。


ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /lib64/libmpc.so.3
ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /lib/libmpc.so.3
ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /usr/lib64/libmpc.so.3
ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /usr/lib/libmpc.so.3
ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /usr/local/lib64/libmpc.so.3
ln -s /usr/local/mpc-1.1.0/lib/libmpc.so.3.1.0 /usr/local/lib/libmpc.so.3

也就是说,大家严格按照本文编译安装MySQL 8.x就不会有这个问题。


九、其他安装方式

如果大家下载的MySQL源码包不是mysql-8.0.18.tar.gz,而是mysql-boost-8.0.18.tar.gz,如下图所示。

MySQL之——源码编译MySQL8.x+升级gcc+升级cmake(亲测完整版)

因为mysql-boost-8.0.18.tar.gz中自带了boost安装文件,在cmake时就不需要下载boost文件了。

如果大家下载的是mysql-boost-8.0.18.tar.gz,则按照如下方式编译安装MySQL。


cd /usr/local/src
tar -zxvf mysql-boost-8.0.18.tar.gz
cd mysql-8.0.18
cmake3 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/data/mysql/data -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=ON -DWITH_INNODB_MEMCACHED=ON -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DCOMPILATION_COMMENT="binghe edition"  -DWITH_BOOST=/usr/local/src/mysql-8.0.18/boost/boost_1_70_0 -DMYSQL_UNIX_ADDR=/data/mysql/run/mysql.sock -DMYSQL_TCP_PORT=3306 -DSYSCONFDIR=/data/mysql/conf -DWITH_READLINE=1 -DFORCE_INSOURCE_BUILD=1 -DWITH_SSL=system -DWITH_ZLIB=system   -DCMAKE_CXX_COMPILER=/usr/local/gcc-9.2.0/bin/g++ -DCMAKE_C_COMPILER=/usr/local/gcc-9.2.0/bin/gcc
gmake -j $(nproc)
gmake install -j $(nproc)


与编译安装mysql-8.0.18.tar.gz源码包相比,编译安装mysql-boost-8.0.18.tar.gz时,使用cmake命令预编译时,去掉了参数-DDOWNLOAD_BOOST=1,并且将参数-DWITH_BOOST=/data/mysql/tmp,修改为-DWITH_BOOST=/usr/local/src/mysql-8.0.18/boost/boost_1_70_0。也就是说,在mysql-boost-8.0.18.tar.gz源码包中,boost安装文件存放在,解压后的mysql-8.0.18目录下的boost/boost_1_70_0目录下。


至此,整个编译安装与测试过程完美结束。


十、下载文件

大家可以到链接:https://download.csdn.net/download/l1028386804/11992200 下载升级gcc与cmake所需的安装文件,到链接:https://download.csdn.net/download/l1028386804/11992212 下载MySQL 8.0.18源码安装文件。

上一篇:bboss多数据库事务管理


下一篇:第十二篇:Flink 常用的 Source 和 Connector