【昌哥IT课堂】MySQL8.0新特性之特权连接
概述:
ERROR 1040 (HY000): Too many connections
上面这个报错,开发或DBA一般都遇见过。那么碰到这个问题,我们应该怎么办呢?
在MySQL 5.7及之前版本,出现“too many connection”报错,超级用户root也无法登录上去,除了重启实例,没有其他更好的解决办法;
到了MySQL 8.0之后的版本中,对连接管理做了一些优化。
连接管理:
在MySQL 8.0版本中,对连接管理这一块,是先后做了两个比较大的改变:一个是允许额外连接,另一个是专用的管理端口。
额外的连接:
在MySQL 8.0版本中,在当前连接数达到最大连接数时,服务端允许1个额外连接,可以让具有SERVICE_CONNECTION_ADMIN权限的用户连接进来:
配置案例:
先调整最大连接数
mysql> set global max_connections=3;
Query OK, 0 rows affected (0.00 sec)
mysql> select @@max_connections;
+-------------------+
| @@max_connections |
+-------------------+
| 3 |
+-------------------+
1 row in set (0.00 sec)
创建普通用户:
mysql> create user general@'%' identified by 'Shukuinfo123.';
Query OK, 0 rows affected (0.11 sec)
mysql> grant select on *.* to general@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
通过general用户建立三个会话连接,数据库中显示如下:
[root@mysql-8034 ~]# mysql -ugeneral -p'Shukuinfo123.' -P3306 -hlocalhost --protocol=tcp
mysql> show processlist;
+----+---------+-----------------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+---------+-----------------+------+---------+------+-------+------------------+
| 12 | general | localhost:33042 | NULL | Query | 0 | init | show processlist |
| 13 | general | localhost:33044 | NULL | Sleep | 9 | | NULL |
| 14 | general | localhost:33046 | NULL | Sleep | 4 | | NULL |
+----+---------+-----------------+------+---------+------+-------+------------------+
3 rows in set (0.01 sec)
mysql> show global status like 'threads_connected';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 3 |
+-------------------+-------+
1 row in set (0.03 sec)
普通用户general再尝试连接,报错too many connections
[root@mysql-8034 ~]# mysql -ugeneral -p'Shukuinfo123.' -P3306 -hlocalhost --protocol=tcp
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1040 (08004): Too many connections
这时如果通过超级用户root来尝试连接,则可以成功建立
[root@mysql-8034 ~]# mysql -uroot -p'Shukuinfo123.' --protocol=tcp -hlocalhost
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 17
Server version: 8.0.34 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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.
再次查看当前连接数为4 (max_connections+1)
mysql> show processlist;
+----+-----------------+-----------------+------+---------+-------+------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-----------------+-----------------+------+---------+-------+------------------------+------------------+
| 5 | event_scheduler | localhost | NULL | Daemon | 10543 | Waiting on empty queue | NULL |
| 12 | general | localhost:33042 | NULL | Sleep | 116 | | NULL |
| 13 | general | localhost:33044 | NULL | Sleep | 150 | | NULL |
| 14 | general | localhost:33046 | NULL | Sleep | 145 | | NULL |
| 17 | root | localhost:33050 | NULL | Query | 0 | init | show processlist |
+----+-----------------+-----------------+------+---------+-------+------------------------+------------------+
5 rows in set (0.00 sec)
如果超级用户root再次尝试连接,也会报错too many connections
[root@mysql-8034 ~]# mysql -uroot -p'Shukuinfo123.' --protocol=tcp -hlocalhost
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1040 (HY000): Too many connections
通过上面测试可知,在MySQL 8.0中,允许的连接数为max_connections+1,其中这1个额外连接,只允许具有SERVICE_CONNECTION_ADMIN权限的用户使用。通过这1个额外连接,DBA可以使用超级用户root连接,进行kill会话等管理操作,以避免直接重启实例,降低成本,提高效率。
专用的连接管理:
>>如在Connection Volume Management中提到的那样,为了满足在已经建立了用于普通连接的接口上已有 max_connections 连接时执行管理操作的需要,MySQL 服务器允许拥有 CONNECTION_ADMIN 权限(或SUPER权限)的用户进行单个管理连接。
它允许具有SERVICE_CONNECTION_ADMIN权限的用户,通过特定的IP和PORT连接上来,且没有连接数限制
此外,在 MySQL 8.0.14 版本中,服务器允许为管理连接专用一个 TCP/IP 端口,如下节所述。
• 管理接口特性
• 支持加密连接的管理接口
>>管理接口特性:
管理连接接口具有以下特点:
• 仅当 admin_address 系统变量在启动时设置为指示其 IP 地址时,服务器才会启用该接口。如果未设置 admin_address,则服务器不维护任何管理接口。
• admin_port 系统变量指定接口的 TCP/IP 端口号(默认为 33062)。
• 管理连接的数量没有限制,但仅允许拥有 SERVICE_CONNECTION_ADMIN 权限的用户连接。
• create_admin_listener_thread 系统变量允许 DBA 在启动时选择管理接口是否拥有自己的独立线程。默认值为 OFF;也就是说,主接口上的普通连接的管理线程也处理管理接口的连接。
在一台没有配置管理连接特性的实例中,查看与admin相关的参数信息如下:
mysql> show variables like '%admin%';
+---------------------------------+---------+
| Variable_name | Value |
+---------------------------------+---------+
| admin_address | | #监听IP地址
| admin_port | 33062 | #监听端口
| admin_ssl_ca | |
| admin_ssl_capath | |
| admin_ssl_cert | |
| admin_ssl_cipher | |
| admin_ssl_crl | |
| admin_ssl_crlpath | |
| admin_ssl_key | |
| admin_tls_ciphersuites | |
| admin_tls_version | TLSv1.2 |
| create_admin_listener_thread | OFF | #是否创建一个单独的线程来监听管理连接
| log_slow_admin_statements | OFF |
| persist_only_admin_x509_subject | |
+---------------------------------+---------+
14 rows in set (0.01 sec)
>>配置案例:
>>配置管理端口:
在服务器的 my.cnf 文件中的这些行启用了管理接口,并配置其使用端口号 33064(即与默认端口3306不同的端口):
[mysqld]
admin_address=127.0.0.1
admin_port=33064
重启数据库实例:
systemctl restart mysqld
查看mysql实例监听的端口:
[root@mysql-8034 ~]# netstat -lntup | grep mysqld
tcp 0 0 127.0.0.1:33064 0.0.0.0:* LISTEN 1530/mysqld
tcp6 0 0 :::3306 :::* LISTEN 1530/mysqld
tcp6 0 0 :::33060 :::* LISTEN 1530/mysqld
[root@mysql-8034 ~]# lsof -i:33064
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 1530 mysql 23u IPv4 24932 0t0 TCP localhost:33064 (LISTEN)
[root@mysql-8034 ~]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 1530 mysql 25u IPv6 24
可以看到,在同一个进程中,有两个端口监听,一个是3306,一个是33064
create_admin_listener_thread变量:
当我们开启create_admin_listener_thread变量时,管理端口将使用独立的线程:
编辑my.cnf配置文件,添加create_admin_listener_thread参数为ON:
[mysqld]
admin_address=127.0.0.1
admin_port=33064
create_admin_listener_thread=on
重启数据库实例:
systemctl restart mysqld
查看新创建的线程,线程名:con_admin-0
[root@mysql-8034 ~]# ps -ef | grep mysqld
mysql 1815 1 10 16:18 ? 00:00:07 /usr/sbin/mysqld
root 1868 1389 0 16:19 pts/0 00:00:00 grep --color=auto mysqld
[root@mysql-8034 ~]# ps -T -p 1815 | grep con_admin-0
1815 1863 ? 00:00:00 con_admin-0
>>客户端连接:
MySQL 客户端程序通过指定适当的连接参数连接到主接口或管理接口。如果在本地主机上运行的服务器使用默认的 TCP/IP 端口号 3306 和 33064 分别用于主接口和管理接口,以下命令将连接到这些接口:
mysql --protocol=TCP --port=3306
mysql --protocol=TCP --port=33064
>>普通用户连接到不同的端口:
创建普通用户:
mysql> create user general@'%' identified by 'Shukuinfo123.';
Query OK, 0 rows affected (0.11 sec)
mysql> grant select on *.* to general@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
>>>用户连接到3306端口:
[root@mysql-8034 ~]# mysql -ugeneral -p'Shukuinfo123.' -h127.0.0.1 -P3306
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 13
Server version: 8.0.34 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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.
mysql> \s
--------------
mysql Ver 8.0.34 for Linux on x86_64 (MySQL Community Server - GPL)
Connection id: 13
Current database:
Current user: general@localhost
SSL: Cipher in use is ECDHE-RSA-AES128-GCM-SHA256
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 8.0.34 MySQL Community Server - GPL
Protocol version: 10
Connection: 127.0.0.1 via TCP/IP
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
TCP port: 3306
Binary data as: Hexadecimal
Uptime: 19 min 51 sec
Threads: 4 Questions: 24 Slow queries: 0 Opens: 150 Flush tables: 3 Open tables: 69 Queries per second avg: 0.020
--------------
可以正常连接到3306端口
>>>用户连接到33064管理端口:
[root@mysql-8034 ~]# mysql -ugeneral -p'Shukuinfo123.' -h127.0.0.1 -P33064
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1227 (42000): Access denied; you need (at least one of) the SERVICE_CONNECTION_ADMIN privilege(s) for this operation
直接报错,提示用户需要有SERVICE_CONNECTION_ADMIN权限才能连接
为general用户授予SERVICE_CONNECTION_ADMIN权限:
mysql> grant SERVICE_CONNECTION_ADMIN on *.* to general@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
再次通过general用户连接到管理端口:
[root@mysql-8034 ~]# mysql -ugeneral -p'Shukuinfo123.' -h127.0.0.1 -P33064
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 12
Server version: 8.0.34 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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.
mysql> \s
--------------
mysql Ver 8.0.34 for Linux on x86_64 (MySQL Community Server - GPL)
Connection id: 12
Current database:
Current user: general@localhost
SSL: Cipher in use is ECDHE-RSA-AES128-GCM-SHA256
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 8.0.34 MySQL Community Server - GPL
Protocol version: 10
Connection: 127.0.0.1 via TCP/IP
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
TCP port:33064
Binary data as: Hexadecimal
Uptime: 18 min 0 sec
Threads: 3 Questions: 20 Slow queries: 0 Opens: 150 Flush tables: 3 Open tables: 69 Queries per second avg: 0.018
--------------
通过为用户授予SERVICE_CONNECTION_ADMIN权限后,就可以正常通过管理端口连接数据库了。
>>验证管理端口会话连接数与max_connections参数的关系:
重新配置max_connections参数,并配置为3
mysql> set global max_connections=3;
Query OK, 0 rows affected (0.00 sec)
mysql> select @@max_connections;
+-------------------+
| @@max_connections |
+-------------------+
| 3 |
+-------------------+
1 row in set (0.00 sec)
>>使用普通用户连接,同时开启3个会话:
普通用户的权限:
mysql> show grants for general@'%';
+--------------------------------------+
| Grants for general@% |
+--------------------------------------+
| GRANT SELECT ON *.* TO `general`@`%` |
+--------------------------------------+
1 row in set (0.00 sec)
打开3个不同的终端,运行连接数据库的命令,如下:
[root@mysql-8034 ~]# mysql -ugeneral -p'Shukuinfo123.' -P3306 -hlocalhost
查看会话信息,显示有3个会话:
mysql> show processlist;
+----+---------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+---------+-----------+------+---------+------+-------+------------------+
| 15 | general | localhost | NULL | Query | 0 | init | show processlist |
| 16 | general | localhost | NULL | Sleep | 63 | | NULL |
| 17 | general | localhost | NULL | Sleep | 52 | | NULL |
+----+---------+-----------+------+---------+------+-------+------------------+
3 rows in set (0.01 sec)
当再建立一个连接(第4个连接)时,报错如下:
[root@mysql-8034 ~]# mysql -ugeneral -p'Shukuinfo123.' -P3306 -hlocalhost
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1040 (08004): Too many connections
以上说明,普通用户受系统参数max_connections的限制,当超过max_connections配置的值时(这里配置为3),数据库将直接拒绝连接!
>>通过管理端口连接到数据库:
创建具有 SERVICE_CONNECTION_ADMIN 权限的用户:
mysql> create user manager@'%' identified by 'Shukuinfo123.';
Query OK, 0 rows affected (0.10 sec)
mysql> grant select,SERVICE_CONNECTION_ADMIN on *.* to manager@'%';
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)
通过manager用户连接到33064端口:
[root@mysql-8034 ~]# mysql -umanager -p'Shukuinfo123.' -P33064 -hlocalhost --protocol=tcp
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 28
Server version: 8.0.34 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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.
mysql> \s
--------------
mysql Ver 8.0.34 for Linux on x86_64 (MySQL Community Server - GPL)
Connection id: 28
Current database:
Current user: manager@localhost
SSL: Cipher in use is ECDHE-RSA-AES128-GCM-SHA256
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 8.0.34 MySQL Community Server - GPL
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
TCP port: 33064
Binary data as: Hexadecimal
Uptime: 16 min 11 sec
Threads: 2 Questions: 72 Slow queries: 0 Opens: 232 Flush tables: 3 Open tables: 166 Queries per second avg: 0.074
--------------
mysql> show processlist;
+----+---------+-----------------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+---------+-----------------+------+---------+------+-------+------------------+
| 22 | manager | localhost:41992 | NULL | Query | 0 | init | show processlist |
| 23 | manager | localhost:41996 | NULL | Sleep | 19 | | NULL |
| 24 | manager | localhost:42000 | NULL | Sleep | 14 | | NULL |
| 25 | manager | localhost:42004 | NULL | Sleep | 9 | | NULL |
| 26 | manager | localhost:42008 | NULL | Sleep | 4 | | NULL |
+----+---------+-----------------+------+---------+------+-------+------------------+
5 rows in set (0.01 sec)
通过manager用户,已建立了5个会话,而系统参数max_connections的配置为3
通过管理端口33064进行连接的用户,不受系统参数max_connections的限制
注意:
如果不是通过端口33064进行连接的用户,还是受max_connections的限制,即使用户具有
SERVICE_CONNECTION_ADMIN权限
下面还是使用manager用户(具有SERVICE_CONNECTION_ADMIN权限),连接到数据库,但连接数据库不是通过端口33064,而是通过本地的SOCKET协议
[root@mysql-8034 ~]# mysql -umanager -p'Shukuinfo123.' -P33064 -hlocalhost
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 29
Server version: 8.0.34 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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.
You are enforcing ssl connection via unix socket. Please consider
switching ssl off as it does not make connection via unix socket
any more secure.
mysql> \s
--------------
mysql Ver 8.0.34 for Linux on x86_64 (MySQL Community Server - GPL)
Connection id: 29
Current database:
Current user: manager@localhost
SSL: Cipher in use is ECDHE-RSA-AES128-GCM-SHA256
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 8.0.34 MySQL Community Server - GPL
Protocol version: 10
Connection:Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/lib/mysql/mysql.sock
Binary data as: Hexadecimal
Uptime: 18 min 25 sec
Threads: 2 Questions: 77 Slow queries: 0 Opens: 232 Flush tables: 3 Open tables: 166 Queries per second avg: 0.069
--------------
mysql>
mysql> show grants for manager@'%';
+--------------------------------------------------------+
| Grants for manager@% |
+--------------------------------------------------------+
| GRANT SELECT ON *.* TO `manager`@`%` |
| GRANT SERVICE_CONNECTION_ADMIN ON *.* TO `manager`@`%` |
+--------------------------------------------------------+
mysql> select @@max_connections;
+-------------------+
| @@max_connections |
+-------------------+
| 3 |
+-------------------+
1 row in set (0.00 sec)
2 rows in set (0.00 sec)
用户manager具有SERVICE_CONNECTION_ADMIN权限,但是通过本地的SOCKET协议连接到数据库,系统max_connections参数的总的连接数限制为3
当建立3个会话后:
mysql> show processlist;
+----+---------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+---------+-----------+------+---------+------+-------+------------------+
| 29 | manager | localhost | NULL | Sleep | 109 | | NULL |
| 30 | manager | localhost | NULL | Sleep | 7 | | NULL |
| 31 | manager | localhost | NULL | Query | 0 | init | show processlist |
+----+---------+-----------+------+---------+------+-------+------------------+
3 rows in set (0.00 sec)
当再次建立第5个连接时,报以下错误
[root@mysql-8034 ~]# mysql -umanager -p'Shukuinfo123.' -P33064 -hlocalhost
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1040 (HY000): Too many connections
为什么不是第4个会话报错,而是第5个会话报错呢?
因为具有SERVICE_CONNECTION_ADMIN权限的用户,可以建立max_connections+1个会话
当建立第5个会话时,已将所有可用的会话全部用完了,所以会报ERROR 1040 (HY000): Too many connections 错误
管理接口支持加密连接
在 MySQL 8.0.21 之前,管理接口支持使用适用于主接口的连接加密配置的加密连接。
从 MySQL 8.0.21 开始,管理接口具有自己的加密连接配置参数。这些参数与主接口参数相对应,但允许独立配置管理接口的加密连接:
• admin_tls_xxx 和 admin_ssl_xxx 系统变量类似于 tls_xxx 和 ssl_xxx 系统变量,但它们配置管理接口的 TLS 上下文,而不是主接口。
• --admin-ssl 选项类似于 --ssl 选项,但它启用或禁用管理接口上的加密连接支持,而不是主接口。
由于默认情况下启用了对加密连接的支持,通常不需要指定 --admin-ssl。从 MySQL 8.0.26 开始,--admin-ssl 已被弃用,并可能在未来的 MySQL 版本中被移除。
有关配置连接加密支持的一般信息,请参阅“配置 MySQL 使用加密连接”第 6.3.1 节和“加密连接 TLS 协议和密码”第 6.3.2 节。该讨论是针对主连接接口编写的,但参数名称对于管理连接接口是相似的。结合该讨论以及以下说明,提供了有关管理接口的特定信息。
管理接口的 TLS 配置遵循以下规则:
• 如果启用了 --admin-ssl(默认情况下),管理接口支持加密连接。对于接口上的连接,适用的 TLS 上下文取决于是否配置了任何非默认的管理 TLS 参数:
• 如果所有管理 TLS 参数都具有其默认值,则管理接口使用与主接口相同的 TLS 上下文。
• 如果任何管理 TLS 参数具有非默认值,则管理接口使用由其自身参数定义的 TLS 上下文。(如果任何 admin_tls_xxx 或 admin_ssl_xxx 系统变量设置为与其默认值不同的值,则是这种情况。)如果无法从这些参数创建有效的 TLS 上下文,则管理接口将退回到主接口的 TLS 上下文。
• 如果禁用了 --admin-ssl(例如,通过指定 --admin-ssl=OFF),则禁用对管理接口的加密连接。即使管理 TLS 参数具有非默认值,也是如此,因为禁用 --admin-ssl 优先。
还可以在不指定否定形式的 --admin-ssl 的情况下禁用管理接口上的加密连接。将 admin_tls_version 系统变量设置为空值表示不支持任何 TLS 版本。例如,在服务器的 my.cnf 文件中,以下行禁用了管理接口上的加密连接:
[mysqld]
admin_tls_version=''
示例:
• 服务器的 my.cnf 文件中的此配置启用了管理接口,但未设置特定于该接口的任何 TLS 参数:
[mysqld]
admin_address=127.0.0.1
因此,管理接口支持加密连接(因为在启用管理接口时,默认情况下支持加密),并使用主接口的 TLS 上下文。当客户端连接到管理接口时,它们应使用与主接口上的普通连接相同的证书和密钥文件。例如(在一行中输入命令):
mysql --protocol=TCP --port=33064
--ssl-ca=ca.pem
--ssl-cert=client-cert.pem
--ssl-key=client-key.pem
• 此服务器配置启用了管理接口并设置了特定于该接口的 TLS 证书和密钥文件参数:
[mysqld]
admin_address=127.0.0.1
admin_ssl_ca=admin-ca.pem
admin_ssl_cert=admin-server-cert.pem
admin_ssl_key=admin-server-key.pem
配置案例:
添加参数到my.cnf文件中:
[mysqld]
admin_address=127.0.0.1
admin_port=33064
create_admin_listener_thread=on
admin_ssl_ca=/var/lib/mysql/ca.pem
admin_ssl_cert=/var/lib/mysql/server-cert.pem
admin_ssl_key=/var/lib/mysql/server-key.pem
以上配置,并重启实例后,相关参数文件会在参数变量中:
mysql> show variables like '%admin%';
+---------------------------------+--------------------------------+
| Variable_name | Value |
+---------------------------------+--------------------------------+
| admin_address | 127.0.0.1 |
| admin_port | 33064 |
| admin_ssl_ca | /var/lib/mysql/ca.pem |
| admin_ssl_capath | |
| admin_ssl_cert | /var/lib/mysql/server-cert.pem |
| admin_ssl_cipher | |
| admin_ssl_crl | |
| admin_ssl_crlpath | |
| admin_ssl_key | /var/lib/mysql/server-key.pem |
| admin_tls_ciphersuites | |
| admin_tls_version | TLSv1.2 |
| create_admin_listener_thread | ON |
| log_slow_admin_statements | OFF |
| persist_only_admin_x509_subject | |
+---------------------------------+--------------------------------+
14 rows in set (0.01 sec)
因此,管理接口支持使用自己的 TLS 上下文进行加密连接。当客户端连接到管理接口时,它们应使用特定于该接口的证书和密钥文件。例如(在命令行行中输入命令):
mysql --protocol=TCP --port=33064
--ssl-ca=admin-ca.pem
--ssl-cert=admin-client-cert.pem
--ssl-key=admin-client-key.pem