一 前言 作为MySQL DBA, 在运维MySQL的工作过程中,常常遇到Too many connections这个错误,这时作为数据库维护人员都不能登陆数据库进行维护 是多么窘迫的事。可能有人会说可以修改配置文件,然后重启数据库来解决。恩,不过这个是很多种解决方法中 可用性最差的一种,本文介绍通过 5.6 新的特性--管理端口 来解决这个问题。 二 认识 extra_port MySQL 在5.6.14 版本之后引入一个参数extra_port 用来解决too many connections的问题。 percona 官方介绍: 从官方文档介绍来看,在MySQL启动的时候使用该参数指定一个端口号(不要和正常的数据库服务端口冲突),Percona Server会监听来自该端口的请求。启用该参数可以解决使用thread_pool特性时,由于所有的连接池worker忙于处理慢querey或者被锁定导致DBA无法通过正常的端口连接DB, 以便DBA可以正常维护数据库。 具体用法如下:mysql --port="extra-port-number" --protocol=tcp Maridb 官方介绍 (和percona的介绍类似,读者朋友可以自己翻译)Description: Extra port number to use for tcp-connections in a one-thread-per-connection manner. If set to 0, no other port is used. Introduced for the MariaDB 5.1 threadpool. extra_max_connections 该参数主要是控制通过管理端口可以创建多少个连接。 官方介绍: "This variable can be used to specify the maximum allowed number of connections plus one extra SUPER users connection on the extra_port. This can be used with the extra_port variable to access the server in case no new connections can be established due to all worker threads being busy or being locked when pool-of-threads feature is enabled." 三 extra_port 测试 测试环境:5.6.26-74.0-log Percona Server 参数设置:max_connections = 1