暂无图片
暂无图片
2
暂无图片
暂无图片
暂无图片

MySQL 8.0新特性之管理端口

原创 闫建 云和恩墨 2022-12-12
2329

概念描述

从MySQL8.0.14开始,MySQL增加了一个新功能:管理端口,官方术语Administrative Connection Management,通俗讲就是给管理员或者DBA增加了一个专门用于管理的连接端口,不受max_connections参数限制,完美解决too many connecitons 连接数满错误导致不得不重启数据库实例来释放连接的问题,即使达到最大连接数上限,也可以通过这个管理端口进行数据库连接后进行相关操作。
该特性主要涉及以下相关知识点:

  • admin_address 管理地址,可以为单独的IPV4、IPV6地址或者主机名,不可以包含通配符,默认为空(未开启该功能)。
  • admin_port 管理端口,用户通过该端口登陆MySQL,默认为33062。
  • create_admin_listener_thread 是否为管理接口单独创建监听线程,默认OFF 不单独创建。
  • 管理端口功能需要用户最低具有SERVICE_CONNECTION_ADMIN权限
  • 管理端口连接支持加密连接
root@127.0.0.1:(none) 08:56:01 >show global variables like 'admin%';
+------------------------+-----------------+
| Variable_name          | Value           |
+------------------------+-----------------+
| admin_address          |                 |
| 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,TLSv1.3 |
+------------------------+-----------------+
11 rows in set (0.00 sec)

测试验证

admin_address参数需要重启,不能动态修改
admin_address = 127.0.0.1
admin_port = 9999
调整参数,重启MySQL,并将max_connections调整为1

root@127.0.0.1:(none) 10:32:53 >show processlist;
+----+------+-----------------+------+---------+------+-------+------------------+
| Id | User | Host            | db   | Command | Time | State | Info             |
+----+------+-----------------+------+---------+------+-------+------------------+
| 26 | root | localhost:33606 | NULL | Sleep   |   14 |       | NULL             |
| 27 | root | localhost:33608 | NULL | Query   |    0 | init  | show processlist |
+----+------+-----------------+------+---------+------+-------+------------------+
2 rows in set (0.01 sec)

再次打开一个会话进行登录后,报错如下:
[root@c1 ~]# mysql -uroot -p'mysql8030' -P 8030 
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1040 (HY000): Too many connections
报错Too many connections 无法登录数据库。


此时通过设置的管理地址 127.0.0.1 和管理端口9999 进行登录
[root@c1 ~]# mysql -uroot -p'mysql8030' -P 9999 -h 127.0.0.1
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.30 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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@127.0.0.1:(none) 10:35:58 >show processlist;
+----+------+-----------------+------+---------+------+-------+------------------+
| Id | User | Host            | db   | Command | Time | State | Info             |
+----+------+-----------------+------+---------+------+-------+------------------+
| 26 | root | localhost:33606 | NULL | Sleep   |  200 |       | NULL             |
| 27 | root | localhost:33608 | NULL | Sleep   |  186 |       | NULL             |
| 28 | root | localhost:43982 | NULL | Query   |    0 | init  | show processlist |
+----+------+-----------------+------+---------+------+-------+------------------+
3 rows in set (0.00 sec)


如上所示可以正常登录。并且用管理端口9999登录,且不限制连接数量。
root@127.0.0.1:(none) 10:38:39 >show global variables like 'admin%';
+------------------------+-----------------+
| Variable_name          | Value           |
+------------------------+-----------------+
| admin_address          | 127.0.0.1       |
| admin_port             | 9999            |
| 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,TLSv1.3 |
+------------------------+-----------------+
11 rows in set (0.02 sec)

功能总结

对于MySQL生产服务器设置管理端口是一个非常有必要的选择,这在应用连接数据库造成连接数爆满场景非常适合,当连接数满后,无法登录数据库,只能通过实例重启解决,无法登录数据库进行问题分析,这样对于排查问题非常不利,故MySQL8.0建议开启该功能。

参考文档

https://dev.mysql.com/doc/refman/8.0/en/administrative-connection-interface.html

最后修改时间:2022-12-14 09:41:43
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论