300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > MySQL 8.0.22 源码编译安装全过程

MySQL 8.0.22 源码编译安装全过程

时间:2023-05-14 02:53:59

相关推荐

MySQL 8.0.22 源码编译安装全过程

墨墨导读:Mysql的8.0版本出来已经有一段时间了,近期研究下源码调试。整个编译过程越来越复杂了。

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

8.0 版本源码编译的同仁,需要把整个内容看完。

1. MySQL 8.0安装对于操作系统的要求

2. 环境:

OS系统:CentOS Linux release 7.9. (Core)

MySQL版本8.0.22

预留额外空间:20G

3.安装部署

3.1. 下载软件

下载/downloads/mysql/

版本选择如下mysql-boost-8.0.22.tar.gz(为了方便直接下载boost携带版本)

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

官方网站下载:/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 --versiongcc (GCC) 4.8.5 0623 (Red Hat 4.8.5-44)[root@ens8 bin]# /usr/bin/g++ --versiong++ (GCC) 4.8.5 0623 (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 specifywget ftp:///gnu/mpc/mpc-1.1.0.tar.gz-P /usr/local/srcwget ftp:///gnu/gmp/gmp-6.1.2.tar.bz2 -P /usr/local/srcwget /gnu/mpfr/mpfr-4.0.2.tar.gz -P /usr/local/srcwget /gnu/m4/m4-1.4.18.tar.gz-P /usr/local/srcwget /gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz -P /usr/local/srctar -zxvf mpc-1.1.0.tar.gztar -zxvf mpfr-4.0.2.tar.gztar -jxvf gmp-6.1.2.tar.bz2tar -zxvf m4-1.4.18.tar.gztar -zxvf gcc-9.2.0.tar.gz--解压gmp需要yum install bzip2 -ymkdir -p /usr/local/m4-1.4.18mkdir -p /usr/local/gmp-6.1.2mkdir -p /usr/local/mpfr-4.0.2mkdir -p /usr/local/mpc-1.1.0mkdir -p /usr/local/gcc-9.2.0cd m4-1.4.18./configure --prefix=/usr/local/m4-1.4.18make && make installln -s /usr/local/m4-1.4.18/bin/m4 /usr/bin/m4cd gmp-6.1.2./configure --prefix=/usr/local/gmp-6.1.2 make && make installcd mpfr-4.0.2./configure --prefix=/usr/local/mpfr-4.0.2/ --with-gmp=/usr/local/gmp-6.1.2/make && make installcd 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.confinclude 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# ldconfigcd 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.5mv /usr/bin/g++ /usr/bin/g++4.8.5ln -s /usr/local/gcc-9.2.0/bin/gcc /usr/bin/gccln -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

备注:这里开启DWITH_DEBUG模式,为了后面调试代码。

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

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

建议还是直接下载编译好的tar包。还有编译需要20G的空间:mysql源码空间10G,gcc大概7G。

时间大概评估下来倩倩后后6个小时。

4. 问题点(重点)

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

-- Running cmake version 2.8.12.2CMake 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/lib64cd /usr/lib64ln -s libstdc++.so.6.0.27 libstdc++.so.6

[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/: 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/: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/.o] Error 1make[1]:***[storage/innobase/CMakeFiles/innobase.dir/all]Error

解决办法:在源文件storage/innobase/buf/的开头添加:#include “sys/syscall.h”

一定要写在第一位

5)错误:make 构建源代码

[ 60%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/lock/.o[ 60%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/lock/.o/opt/idc/debug/mysql-8.0.22/storage/innobase/lock/: 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/: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/: In function ‘void trx_init(trx_t*)’:/opt/idc/debug/mysql-8.0.22/storage/innobase/trx/: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/: In function ‘void trx_kill_blocking(trx_t*)’:/opt/idc/debug/mysql-8.0.22/storage/innobase/trx/: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/.o] Error 1make[1]: *** [storage/innobase/CMakeFiles/innobase.dir/all] Error 2

解决办法:替换源文件中os_compare_and_swap_thread_id为os_compare_and_swap_lint

需要更改3个地方:

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

总结

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

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

作者

崔虎龙:云和恩墨MySQL技术顾问,长期服务于金融、游戏、物流等行业的数据中心,设计数据存储架构,并熟悉数据中心运营管理的流程及规范,自动化运维等。擅长MySQL、Redis、MongoDB数据库高可用设计和运维故障处理、备份恢复、升级迁移、性能优化。自学通过了MySQL OCP 5.6和MySQL OCP 5.7认证。2年多开发经验,数据库运维工作经验,其中专职做MySQL工作8年;曾经担任过项目经理、数据库经理、数据仓库架构师、MySQL技术专家、DBA等职务;涉及行业:金融(银行、理财)、物流、游戏、医疗、重工业等。

墨天轮原文链接:https://www.modb.pro/db/42279(复制到浏览器中打开或者点击“阅读原文”立即查看)

推荐阅读:267页!度数据库技术年刊

推荐下载:数据技术嘉年华PPT下载

数据技术嘉年华近50个PPT下载、视频回放已上传墨天轮平台,可在“数据和云”公众号回复关键词“DTC”获得!

视频号,新的分享时代,关注我们,看看有什么新发现?

数据和云

ID:OraNews

如有收获,请划至底部,点击“在看”,谢谢!

点击下图查看更多 ↓

云和恩墨大讲堂 |一个分享交流的地方

长按,识别二维码,加入万人交流社群

请备注:云和恩墨大讲堂

点个“在看”

你的喜欢会被看到❤

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。