The mysql_connections
alert indicates the percentage of used client connections compared to the maximum configured connections. When you receive this alert, it means your MySQL or MariaDB server is reaching its connection limit, which could lead to performance issues or failed connections for clients.
Use the following command to see the current used and total connections:
mysql -u root -p -e "SHOW STATUS LIKE 'max_used_connections'; SHOW VARIABLES LIKE 'max_connections';"
This will display the maximum number of connections used since the server was started and the maximum allowed number of connections (max_connections
).
You can monitor the connection usage over time using the following command:
watch -n 1 "mysql -u root -p -e 'SHOW STATUS LIKE \"Threads_connected\";'"
This will update the number of currently connected threads every second.
If connection usage is high, check which processes or clients are using connections:
mysql -u root -p -e "SHOW PROCESSLIST;"
This gives you an overview of the currently connected clients, their states, and queries being executed.
Analyze the processes using connections and ensure they close their connections properly when done, utilize connection pooling, and reduce the number of connections where possible.
If you need to increase the max_connections
value, follow these steps:
Log into MySQL from the terminal as shown in the troubleshooting section:
mysql -u root -p
Check the current limit:
show variables like "max_connections";
Set a new limit temporarily:
set global max_connections = "LIMIT";
Replace "LIMIT" with the desired new limit.
my.cnf
file (typically under /etc
, but it may vary depending on your installation) and append max_connections = LIMIT
under the [mysqld]
section.Replace "LIMIT" with the desired new limit, then restart the MySQL/MariaDB service.