MySQL 8.4.0 LTS 变更解析:源码编译(类库变更)和密码插件

MySQL 8.4.0 LTS 变更解析:源码编译(类库变更)和密码插件

ShawnYan Lv.6

MySQL 8.4.0 LTS 已经发布 ,作为发版模型变更后的第一个长期支持版本,注定要承担未来生产环境的重任,那么这个版本都有哪些新特性、变更,接下来少安将带大家一起来 get 新知识点。

环境准备

本文涉及到源码编译,先说明下环境信息,操作系统为 Rocky 9。

Tips:

CentOS 7 即将 EOL,建议直接升级到 RHEL 9,如果考虑到费用或者国产化操作系统替代的问题,可以选择 Oracle Linux 9 或者 Rocky Linux 9。

具体信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
[mysql@shawnyan ~]$ cat /etc/redhat-release
Rocky Linux release 9.3 (Blue Onyx)
[mysql@shawnyan ~]$ gcc --version
gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[mysql@shawnyan ~]$ cmake --version
cmake version 3.20.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

编译要求

如果你需要编译 MySQL 8.4.0 源码,那么 CMake 的最小版本需要升级到 3.14.6,之前是 3.5.1。

当然,我这里使用的是 3.20.2,符合最低要求。

编译选项

MySQL 源码编译不在需要添加 BOOST 相关选项:WITH_BOOST, DOWNLOAD_BOOST, DOWNLOAD_BOOST_TIMEOUT

相应代码结构也做了调整:mysql-server/tree/8.4/extra/boost/boost_1_84_0/boost

类库变更

MySQL 8.4.0 类库变更主要体现在3点,

  1. 之前用于 MySQL Router 中的 libevent 类库被移除。
  2. 由于代码实现变更,增加 libcno 类库,取代 libevent ,用于 HTTP 处理。[1]
  3. boost 版本从 1.77.0 升级到 1.84.0 。

插件变更

有如下几个插件被移除,如果延用之前的编译选项,并使用到这些插件,需要注意更改编译选项。

  • authentication_fido, authentication_fido_client : 使用 authentication_webauthn 替代

CMake 的 -DWITH_FIDO 选项被移除。

  • keyring_file : 使用 component_keyring_file 替代

CMake 的 -DINSTALL_MYSQLKEYRINGDIR-DWITH_KEYRING_TEST 选项被移除。

  • keyring_encrypted_file : 使用 component_keyring_encrypted_file 替代

  • keyring_oci : 使用 component_keyring_oci 替代

  • openssl_udf : 使用 MySQL Enterprise Encryption 组件替代

关于 MySQL 组件替换插件的更多内容,请参阅:

源码编译

从 MySQL 官方网站下载 MySQL 8.4.0 源代码。

下载链接: https://dev.mysql.com/downloads/mysql/

解压,并执行编译配置。

1
2
3
4
5
tar zxf mysql-8.4.0.tar.gz
cd mysql-8.4.0
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DEXTRA_VERSION="-ShawnYan"

输出:

1
2
3
4
5
6
7
8
9
10
[mysql@shawnyan build]$ cmake .. -DCMAKE_BUILD_TYPE=Debug -DEXTRA_VERSION="-ShawnYan"
-- Running cmake version 3.20.2
-- Found Git: /usr/bin/git (found version "2.39.3")
-- This is .el9. as found from 'rpm -qf /'
-- Looking for a devtoolset compiler
-- Using /opt/rh/gcc-toolset-12/root/usr/bin/gcc
-- Using /opt/rh/gcc-toolset-12/root/usr/bin/g++
-- CMAKE_MODULE_PATH is /data/mysql-8.4.0/cmake
-- MySQL 8.4.0-ShawnYan
...

配置完成后,执行编译,开始进入漫长的等待。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[mysql@shawnyan build]$ make
[ 0%] Built target absl_log_severity
...
[ 9%] Built target mysql_serialization
[ 9%] Built target mysql_gtid
[ 9%] Built target all_sys_schema
[ 9%] Built target comp_sql
...
[ 91%] Built target sql_dd
[ 92%] Built target rpl_replica
[ 93%] Built target sql_gis
[ 94%] Built target binlog
[ 94%] Built target rpl
[ 97%] Built target innobase
[ 97%] Built target mysqld
[100%] Built target merge_large_tests-t

编译完成,生成的文件约 17G,需要注意磁盘空间,不然编译还没结束磁盘先满了。

1
2
[mysql@shawnyan mysql-8.4.0]$ du -sh build/
17G build/

直接启动数据库。

1
./bin/mysqld --datadir=./data

可以看到数据库服务已经顺利启动

1
2
3
4
5
6
7
8
9
[mysql@shawnyan build]$ ./bin/mysqld --datadir=./data
2024-05-14T06:01:15.883098Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2024-05-14T06:01:16.148917Z 0 [System] [MY-010116] [Server] /data/mysql-8.4.0/build/runtime_output_directory/mysqld (mysqld 8.4.0-ShawnYan-debug) starting as process 55817
2024-05-14T06:01:16.172236Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-05-14T06:01:17.006479Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-05-14T06:01:19.026567Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2024-05-14T06:01:19.026626Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2024-05-14T06:01:19.293313Z 0 [System] [MY-010931] [Server] /data/mysql-8.4.0/build/runtime_output_directory/mysqld: ready for connections. Version: '8.4.0-ShawnYan-debug' socket: '/tmp/mysql.sock' port: 3306 Source distribution.
2024-05-14T06:01:19.563373Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock

连接数据库查看版本信息。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[mysql@shawnyan build]$ ./bin/mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.4.0-ShawnYan-debug Source distribution

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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.

(root@localhost) [(none)] 14:05:17> select version();
+----------------------+
| version() |
+----------------------+
| 8.4.0-ShawnYan-debug |
+----------------------+
1 row in set (0.00 sec)

密码插件

创建一个测试用户,并查看其密码,确认默认使用 caching_sha2_password 插件。

1
2
3
4
5
6
(root@localhost) [(none)] 14:06:28> create user u1 identified by '1';
Query OK, 0 rows affected (0.07 sec)
(root@localhost) [(none)] 14:08:07> show create user u1\G
*************************** 1. row ***************************
CREATE USER for u1@%: CREATE USER `u1`@`%` IDENTIFIED WITH 'caching_sha2_password' AS '$...
1 row in set (0.00 sec)

如果使用 mysql_native_password 插件创建用户,则会遇到报错。

1
2
(root@localhost) [(none)] 14:11:12> create user u1 identified with 'mysql_native_password' by '1';
ERROR 1524 (HY000): Plugin 'mysql_native_password' is not loaded

这也是 MySQL 8.4.0 LTS 中非常重要的一个变更点。

mysql_native_password 认证插件已经被废弃,并且默认被禁用。

目前,仍然可以通过服务器启动选项 --mysql-native-password=ON 来启用。

但是,调用时会抛出警告。

1
2024-05-14T06:14:59.927757Z 9 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'

Tips:

  1. 建议尽快替换为 caching_sha2_password 认证插件。

  2. 从 MySQL 8.0.14 引入的双密码策略,并不支持两种认证插件混用。

总结

本章节我们介绍了编译 MySQL 8.4.0 LTS 源码需要注意几点变更,以及连接数据库时认证插件发生的变化。

下一节我们继续介绍其他新特性,欢迎关注本专栏。

往期精彩

– END –

foot.png

如果这篇文章为你带来了灵感或启发,就请帮忙点『赞』or『在看』or『转发』吧,感谢!(๑˃̵ᴗ˂̵)


  1. https://github.com/pyos/libcno ↩︎

  • Title: MySQL 8.4.0 LTS 变更解析:源码编译(类库变更)和密码插件
  • Author: ShawnYan
  • Created at: 2024-05-14 21:00:00
  • Updated at: 2024-05-14 21:00:00
  • Link: https://shawnyan.cn/2024/mysql/mysql-8-4-0-lts-change-compile-and-password-plugin/
  • License: This work is licensed under CC BY-NC-SA 4.0.
if (hexo-config('comment.enable') == true && hexo-config('comment.system') != "") { if (hexo-config('comment.system') == "waline") { @require "./waline.styl" } else if (hexo-config('comment.system') == "gitalk") { @require "./gitalk.styl" } else if (hexo-config('comment.system') == "twikoo") { @require "./twikoo.styl" } } .comments-container display inline-block margin-top $spacing-unit width 100% #comment-anchor width 100% height 10px .comment-area-title width 100% margin 10px 0 font-size 1.38rem color var(--default-text-color) font-family 'Consolas', '宋体', sans-serif font-weight bold i color var(--default-text-color) +redefine-tablet() margin 5px 0 font-size 1.2rem