Mysql 8.0.22 源码编译安装

近期研究下源码调试,MySQL5.7版本源码安装还是比较简单的,有很多例子参考。所以这次选择MySQL8.0版本,再整源码编译中,踩到了很多坑多。身心交瘁,最终通过不停地尝试中,终于苦尽甘来。
8.0版本源码编译的同仁,需要把整个内容看完。

1.MySQL8.0安装对于操作系统的要求

image.png

2.环境:

OS系统:CentOS Linux release 7.9.2009 (Core)
MySQL版本8.0.22
预留额外空间:20G
image.png

3.安装部署

3.1. 下载软件
下载https://dev.mysql.com/downloads/mysql/
版本选择如下mysql-boost-8.0.22.tar.gz(为了方便直接下载boost携带版本)
image.png

备注:Boost库是一个可移植、提供源代码的C库,作为标准库的后备,是C标准化进程的开发引擎之一。 Boost库由C标准委员会库工作组成员发起,其中有些内容有望成为下一代C标准库内容。在C社区中影响甚大,是不折不扣的“准”标准库。Boost由于其对跨平台的强调,对标准C的强调,与编写平台无关。
官方网站下载:https://www.boost.org/users/download/

3.2. 安装依赖包

# yum -y install gcc gcc-c++ ncurses-devel openssl-devel cmake3 bison wget bzip2
# ln -s /usr/bin/cmake3 /usr/bin/cmake

备注: 这里非常的坑。建议不要用yum按照依赖项: opennssl cmake3之类的

强烈建议按照一下步骤来:

[root@ens8 hsperfdata_root]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)

[root@ens8 bin]# /usr/bin/g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)



####直接安装gcc可能会=会报错,需要安装gmp、mpfr、mpc,各组件前后有关系,按此顺序执行
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify

wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz     -P /usr/local/src
wget ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.bz2    -P /usr/local/src
wget http://ftp.gnu.org/gnu/mpfr/mpfr-4.0.2.tar.gz  -P /usr/local/src
wget http://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.gz     -P /usr/local/src
wget http://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz -P /usr/local/src

tar -zxvf mpc-1.1.0.tar.gz
tar -zxvf mpfr-4.0.2.tar.gz
tar -jxvf gmp-6.1.2.tar.bz2
tar -zxvf m4-1.4.18.tar.gz
tar -zxvf gcc-9.2.0.tar.gz

--解压gmp需要yum install bzip2 -y

mkdir -p /usr/local/m4-1.4.18
mkdir -p /usr/local/gmp-6.1.2
mkdir -p /usr/local/mpfr-4.0.2
mkdir -p /usr/local/mpc-1.1.0
mkdir -p /usr/local/gcc-9.2.0

cd m4-1.4.18
./configure --prefix=/usr/local/m4-1.4.18
make && make install
ln -s /usr/local/m4-1.4.18/bin/m4 /usr/bin/m4

cd  gmp-6.1.2
./configure --prefix=/usr/local/gmp-6.1.2 
make && make install

cd mpfr-4.0.2
./configure --prefix=/usr/local/mpfr-4.0.2/ --with-gmp=/usr/local/gmp-6.1.2/
make && make install

cd mpc-1.1.0
./configure --prefix=/usr/local/mpc-1.1.0 --with-gmp=/usr/local/gmp-6.1.2/ --with-mpfr=/usr/local/mpfr-4.0.2/
make && make install

[root@kenyon ]# more /etc/ld.so.conf
include ld.so.conf.d/*.conf

/usr/local/gmp-6.1.2/lib
/usr/local/mpfr-4.0.2/lib
/usr/local/mpc-1.1.0/lib

# ldconfig

cd gcc-9.2.0
./configure --prefix=/usr/local/gcc-9.2.0 --with-gmp=/usr/local/gmp-6.1.2  --with-mpfr=/usr/local/mpfr-4.0.2 --with-mpc=/usr/local/mpc-1.1.0 --disable-multilib 
make && make install
--编译好久....4个小时左右....

mv /usr/bin/gcc /usr/bin/gcc4.8.5
mv /usr/bin/g++ /usr/bin/g++4.8.5

ln -s /usr/local/gcc-9.2.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-9.2.0/bin/g++ /usr/bin/g++

3.3. 编译
都准备好了编译比较简单,等待时间就可以。30分钟
[root@ss30 mysql-8.0.22]#cmake . -DCMAKE_INSTALL_PREFIX=/opt/idc/debug/mysql
-DMYSQL_DATADIR=/opt/idc/debug/mysql/data
-DWITH_DEBUG=1
-DSYSCONFDIR=/opt/idc/debug
-DMYSQL_TCP_PORT=3384
-DWITH_BOOST=/opt/idc/debug/mysql-8.0.22/boost
-DCMAKE_CXX_COMPILER=/usr/bin/g++
-DFORCE_INSOURCE_BUILD=1
image.png
备注:这里开启DWITH_DEBUG模式,为了后面调试代码。

之后make & make install 命令,漫长的等待

[root@ss30 mysql-8.0.22]#make & make install

建议还是直接下载编译好的tar包。还有编译需要20G的空间:mysql源码空间10G,gcc大概7G。
时间大概评估下来前前后后6个小时。

  1. 问题点,这里非常重点

1)错误:提示Cmake需要3.5.1版本或则更高版本

1)错误:提示Cmake需要3.5.1版本或则更高版本

-- Running cmake version 2.8.12.2
CMake Warning at CMakeLists.txt:43 (MESSAGE):
  Please use cmake3 rather than cmake on this platform
-- Please install cmake3 (yum install cmake3)
CMake Error at CMakeLists.txt:73 (CMAKE_MINIMUM_REQUIRED):
  CMake 3.5.1 or higher is required.  You are running version 2.8.12.2

第一次安装的时,使用最新的cmake3 v3.16~v3.19 发现跟OpenSSL 1.1.1g代码层缺少函数,导致后续无法编译,尝试解决过,但问题太多,最终选择了3.5.1版本。坑很多,怀疑是不是直接用CentOS8 就不会存在问题。

2)错误:构建源代码

Please do not build in-source.  Out-of source builds are highly   recommended: you can have multiple builds for the same source, and there is
  an easy way to do cleanup, simply remove the build directory (note that
  'make clean' or 'make distclean' does *not* work)

  You *can* force in-source build by invoking cmake with
  -DFORCE_INSOURCE_BUILD=1

原因:建议不要构建源代码。

解决办法:在配置的时候加入字段:-DFORCE_INSOURCE_BUILD=1

3)错误:构建源代码

../runtime_output_directory/uca9dump: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ../runtime_output_directory/uca9dump)

原因是升级了gcc,却没有将升级后的gcc的动态库去替换老版本的gcc动态库所致
解决办法:
cp /usr/local/src/gcc-9.2.0/x86_64-pc-linux-gnu/libstdc+±v3/src/.libs/libstdc++.so.6.0.27 /usr/lib64
cd /usr/lib64
ln -s libstdc++.so.6.0.27 libstdc++.so.6
image.png

[root@ens8 src]# cp /usr/local/src/gcc-9.2.0/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.27 /usr/lib64
[root@ens8 lib64]# rm -rf libstdc++.so.6
[root@ens8 lib64]# ln -s libstdc++.so.6.0.27 libstdc++.so.6

4)错误:make 构建源代码

/opt/idc/debug/mysql-8.0.22/storage/innobase/buf/buf0buf.cc: In function ‘void buf_pool_create(buf_pool_t*, ulint, ulint, std::mutex*, dberr_t&)’:
/opt/idc/debug/mysql-8.0.22/storage/innobase/buf/buf0buf.cc:1222:44: error: ‘SYS_gettid’ was not declared in this scope
 1222 |   setpriority(PRIO_PROCESS, (pid_t)syscall(SYS_gettid), -20);
      |                                            ^~~~~~~~~~
make[2]: *** [storage/innobase/CMakeFiles/innobase.dir/buf/buf0buf.cc.o] Error 1
make[1]: *** [storage/innobase/CMakeFiles/innobase.dir/all] Error 2

image.png

解决办法:在源文件storage/innobase/buf/buf0buf.cc的开头添加: #include “sys/syscall.h”
一定要写在第一位
image.png

5)错误:make 构建源代码(8.0.23最新版本 不需要)

[ 60%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/lock/lock0latches.cc.o
[ 60%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/lock/lock0lock.cc.o
/opt/idc/debug/mysql-8.0.22/storage/innobase/lock/lock0lock.cc: In function ‘void lock_mark_trx_for_rollback(hit_list_t&, trx_id_t, trx_t*)’:
/opt/idc/debug/mysql-8.0.22/storage/innobase/lock/lock0lock.cc:1228:9: error: ‘os_compare_and_swap_thread_id’ was not declared in this scope; did you mean ‘os_compare_and_swap_lint’?

 1228 |   cas = os_compare_and_swap_thread_id(&trx->killed_by, 0, thread_id);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |         os_compare_and_swap_lint

/opt/idc/debug/mysql-8.0.22/storage/innobase/trx/trx0trx.cc: In function ‘void trx_init(trx_t*)’:
/opt/idc/debug/mysql-8.0.22/storage/innobase/trx/trx0trx.cc:223:5: error: ‘os_compare_and_swap_thread_id’ was not declared in this scope; did you mean ‘os_compare_and_swap_lint’?
  223 |     os_compare_and_swap_thread_id(&trx->killed_by, thread_id, 0);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |     os_compare_and_swap_lint
/opt/idc/debug/mysql-8.0.22/storage/innobase/trx/trx0trx.cc: In function ‘void trx_kill_blocking(trx_t*)’:
/opt/idc/debug/mysql-8.0.22/storage/innobase/trx/trx0trx.cc:3349:5: error: ‘os_compare_and_swap_thread_id’ was not declared in this scope; did you mean ‘os_compare_and_swap_lint’?
 3349 |     os_compare_and_swap_thread_id(&victim_trx->killed_by, thread_id, 0);


make[2]: *** [storage/innobase/CMakeFiles/innobase.dir/lock/lock0lock.cc.o] Error 1
make[1]: *** [storage/innobase/CMakeFiles/innobase.dir/all] Error 2

解决办法:替换源文件lock0lock.cc中os_compare_and_swap_thread_id为os_compare_and_swap_lint
需要更改3个地方:

vim /opt/idc/debug/mysql-8.0.22/storage/innobase/lock/lock0lock.cc
vim /opt/idc/debug/mysql-8.0.22/storage/innobase/trx/trx0trx.cc

image.png

总结

整个源码安装过程是 非常消耗耐力和时间的一个过程。随着操作系统版本一些硬性要求,一些基础的依赖存在问题。编译过程中碰到的问题,有些是来自于开源社区,有些是自己尝试总结的。

没有特殊要求,建议直接用tar解压使用就可以。

猜你喜欢

转载自blog.csdn.net/dreamyuzhou/article/details/117483004