summaryrefslogtreecommitdiffstats
path: root/health/guides/mysql/mysql_connections.md
diff options
context:
space:
mode:
Diffstat (limited to 'health/guides/mysql/mysql_connections.md')
-rw-r--r--health/guides/mysql/mysql_connections.md74
1 files changed, 74 insertions, 0 deletions
diff --git a/health/guides/mysql/mysql_connections.md b/health/guides/mysql/mysql_connections.md
new file mode 100644
index 00000000..2f57fef2
--- /dev/null
+++ b/health/guides/mysql/mysql_connections.md
@@ -0,0 +1,74 @@
+### Understand the alert
+
+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.
+
+### Troubleshoot the alert
+
+1. **Check the current connection usage**
+
+ 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`).
+
+2. **Monitor connections over time**
+
+ 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.
+
+3. **Identify connection-consuming processes**
+
+ 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.
+
+4. **Optimize client connections**
+
+ 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.
+
+5. **Increase the connection limit (if necessary)**
+
+ 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.
+
+ - To set the limit permanently, locate the `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.
+
+### Useful resources
+
+1. [How to Increase Max Connections in MySQL](https://ubiq.co/database-blog/how-to-increase-max-connections-in-mysql/)
+2. [MySQL 5.7 Reference Manual: SHOW STATUS Syntax](https://dev.mysql.com/doc/refman/5.7/en/show-status.html)
+3. [MySQL 5.7 Reference Manual: SHOW PROCESSLIST Syntax](https://dev.mysql.com/doc/refman/5.7/en/show-processlist.html)
+4. [MySQL 5.7 Reference Manual: mysqld – The MySQL Server](https://dev.mysql.com/doc/refman/5.7/en/mysqld.html)