前情提要
前文已经介绍了如何安装 Rocky Linux 9.2,这里便不再赘述。
同时,也已经介绍过 MySQL 8.2.0 的参数变化,以及提及如何安装 MySQL 8.2.0。
- [MySQL 8.2.0] 从参数变化解读 MySQL 8.2.0 发版说明
- Step by Step 安装 Rocky Linux 9.2 系统
- Step by Step 从 CentOS 7.9 升级到 Rocky Linux 9.2
本文将着重介绍如何编译 MySQL 8.2.0 Debug 版本。
环境准备
本文使用的操作系统为 Rocky Linux 9.2,下面简称 Rocky。
[shawnyan@rocky9 ~]$ cat /etc/redhat-release Rocky Linux release 9.2 (Blue Onyx) [shawnyan@rocky9 ~]$ cmake --version cmake version 3.20.2 CMake suite maintained and supported by Kitware (kitware.com/cmake). [shawnyan@rocky9 ~]$
mysql-server 的源码为 cpp 语言,编译需要用到 cmake,这里已经安装好,版本为 3.20.2。
下载源码
mysql-server 的源码,通常有两种下载途径:
- 从 MySQL 官网下载源码包。
官网下载地址:https://dev.mysql.com/downloads/mysql/
- 从 GitHub 上克隆获取。
git clone https://github.com/mysql/mysql-server.git
源码版本为:mysql-8.2.0, 7307d4
编译源码
下载源码后,进入源码路径,创建一个 debug 文件夹,专门用于编译。
mkdir debug cd debug
由于这次是编译 debug 版本,所以需要将构建类型设定为 debug。
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_BOOST=. make
编译的过程是漫长的,这个时间可以去煮杯咖啡,慢慢等待。
最后,执行 make install
进行安装,这里安装路径选择为默认路径,即 /usr/local/mysql
。
运行 MySQL 8.2.0 Debug 服务器
安装完成后,需要进行数据库初始化。
/usr/local/mysql/bin/mysqld --initialize-insecure
然后启动即可。
[mysql@rocky9 mysql]$ /usr/local/mysql/bin/mysqld 2023-10-30T10:10:05.928804Z 0 [System] [MY-015015] [Server] MySQL Server - start. 2023-10-30T10:10:06.674943Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.2.0-debug) starting as process 70140 2023-10-30T10:10:06.734430Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2023-10-30T10:10:08.003417Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2023-10-30T10:10:09.939694Z 0 [System] [MY-010229] [Server] Starting XA crash recovery... 2023-10-30T10:10:09.945047Z 0 [System] [MY-010232] [Server] XA crash recovery finished. 2023-10-30T10:10:10.141478Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2023-10-30T10:10:10.141636Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. 2023-10-30T10:10:10.460188Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock 2023-10-30T10:10:10.461041Z 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: '8.2.0-debug' socket: '/tmp/mysql.sock' port: 3306 Source distribution. 2023-10-30T10:10:25Z UTC - mysqld got signal 11 ;
这里可以从日志中看到,MySQL 服务器已经启动,版本为:‘8.2.0-debug’。
实验:SHOW PARSE_TREE
新特性
在 [MySQL 8.2.0] 从参数变化解读 MySQL 8.2.0 发版说明 中已经介绍过 SHOW PARSE_TREE
新特性,但该特性仅支持 Debug 版本,所以这里可以进行测试。
示例如下:
show parse_tree select 1\G
输出结果如下:
mysql> show parse_tree select 1\G
*************************** 1. row ***************************
Show_parse_tree: {
"text": "select 1",
"type": "PT_select_stmt",
"components": [
{
"text": "select 1",
"type": "PT_query_expression",
"components": [
{
"text": "select 1",
"type": "PT_query_specification",
"components": [
{
"text": "1",
"type": "PT_select_item_list",
"components": [
{
"text": "1",
"type": "PTI_expr_with_alias",
"components": [
{
"text": "1",
"type": "Item_int"
}
]
}
]
}
]
}
]
}
]
}
1 row in set (0.00 sec)
不过,这里遇到了一个问题,看来这个新特性有严重的bug:
遇到问题
缺包问题
编译过程中会提示缺少类包,好在代码已经做了 catch 及 tips,这里只需依照提示安装对应缺少的包即可,比如:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:92 (MESSAGE): Curses library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel. Call Stack (most recent call first): cmake/readline.cmake:126 (FIND_CURSES) cmake/readline.cmake:220 (MYSQL_USE_BUNDLED_EDITLINE) CMakeLists.txt:1934 (MYSQL_CHECK_EDITLINE)
cmake 过程中遇到报错,提示安装 ncurses-devel
。
yum install ncurses-devel
安装完成后,再次 cmake 通过。
编译报错
编译过程中,遇到报错,似乎无解,只能扩充 VM 资源,再次进行编译。
- 第一次报错
[ 88%] Building CXX object sql/CMakeFiles/sql_gis.dir/gis/overlaps.cc.o g++: fatal error: 已杀死 signal terminated program cc1plus compilation terminated. make[2]: *** [sql/CMakeFiles/sql_gis.dir/build.make:300:sql/CMakeFiles/sql_gis.dir/gis/intersection_functor.cc.o] 错误 1 make[2]: *** 正在等待未完成的任务.... make[1]: *** [CMakeFiles/Makefile2:33773:sql/CMakeFiles/sql_gis.dir/all] 错误 2 make: *** [Makefile:166:all] 错误 2 real 150m33.063s user 192m24.614s sys 33m36.786s [root@rocky9 debug]#
- 第二次报错
[ 61%] Linking CXX executable ../runtime_output_directory/mysqld collect2: fatal error: ld terminated with signal 9 [已杀死] compilation terminated. make[2]: *** [sql/CMakeFiles/mysqld.dir/build.make:157:runtime_output_directory/mysqld] 错误 1 make[2]: *** 正在删除文件“runtime_output_directory/mysqld” make[1]: *** [CMakeFiles/Makefile2:12706:sql/CMakeFiles/mysqld.dir/all] 错误 2 make: *** [Makefile:156:all] 错误 2 real 98m7.350s user 79m50.233s sys 11m1.616s
这里也提示,在编译 MySQL 源码时,机器资源要给多一些,2c2g 是编译不过的。
总结
文本介绍了如何编译 MySQL 8.2.0 源码,及进行了新特性的尝试。
不过,也遇到了一个问题,就是编译时间很长,如上面的编译报错,是在经历 150 分钟后,才抛出报错。