How to find out the reason for MYSQL connection timeout, how to monitor MYSQL recently discovered that the database suddenly died because of too many connections, many processes are waiting, and many tables are locked .. 1. check whether the website has no persistent connections. 2. if interactive_timeout and wait_timeout are both set to 20 seconds, the problem should be caused by some database operations, but where should they be checked. If you do not check the connection in real time, is there a way to find out which connections exceed interact, how to find out the reason for MYSQL connection timeout, and how to monitor MYSQL
Recently, I found that the database suddenly died because of too many connections.
Many processes are waiting, and many tables are locked ..
1. I checked that the website has no persistent connection.
2. interactive_timeout and wait_timeout are both set to 20 seconds.
The problem should be caused by some database operations, but where should I start.
If you do not check the value in real time, is there a way to check which connections exceed the maximum value set by interactive_timeout and wait_timeout.
Or which connections have encountered problems?
In this way, it is easier to find the cause with the record? Let's talk about other methods .. Thank you.
------ Solution --------------------
I usually need to record SQL statements that have been executed for a long time to monitor which programs need improvement to increase the speed.
The method is simple:
Find your mysql configuration file, add one or more sections, and remove the comments.
SQL code
Log_slow_queries =/var/blogguy.cn/log/mysql/mysql-slow.log
Long_query_time = 1
Log-queries-not-using-indexes = true
The first row specifies the record file address, and the second row specifies the long query time. if this time is queried, the second row specifies whether the record does not use the index query.
Save and restart mysql.