Background
MySQL 8.0.14 introduced the admin_port
parameter to mitigate "too many connections" errors by providing a dedicated management port. However, users reported persistent connection failures even after configuring this feature. This article recreates the issue, analyzes root causes, and offers solutions.
Scenario Recreation
Admin Port Configuration Parameters
create_admin_listener_thread = 1 # Enables a dedicated listener thread
admin_address = localhost # Bind address (IPv4/IPv6/hostname)
admin_port = 33062 # Default port (customizable)
Steps to Reproduce
Restart MySQL with the admin port enabled:
systemctl restart mysqld_3306
Verify connectivity via the admin port:
mysql -uroot -p -S /data/mysql/data/3306/mysqld.sock -P33062 -e 'SELECT VERSION()'
Simulate connection exhaustion:
SET GLOBAL max_connections = 1; -- Limit connections to 1
mysql -uroot -p -e 'SELECT VERSION()' -- Triggers "ERROR 1040"
Fault Analysis
Key Observations
- Socket vs. TCP Connections:
Usinglocalhost
inadmin_address
binds the port to127.0.0.1
, while a Unix socket connection ignores the port setting entirely. - Hostname Resolution Issues:
Ifadmin_address
is set tolocalhost
, MySQL resolves it to127.0.0.1
, which may not align with user privileges (e.g., accounts restricted tolocalhost
).
Solution Steps
Bind to a Fixed IP Address:
Update admin_address to 127.0.0.1 in my.cnf:
admin_address = 127.0.0.1
Create a Dedicated Admin Account:
Grant privileges explicitly to the admin port:
CREATE USER 'admin'@'127.0.0.1' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' WITH GRANT OPTION;
FLUSH PRIVILEGES;
mysql -uadmin -p -h127.0.0.1 -P33062 -e 'SELECT VERSION()'
Optimization Recommendations
- Least Privilege Principle: Restrict
SUPER
orSERVICE_CONNECTION_ADMIN
privileges to essential accounts. - Connection Pooling: Configure application data sources with
initialSize
andmaxActive
limits to control concurrency. - SQL Performance Tuning: Optimize slow queries to reduce connection spikes.