mysql slow SQL investigation of the show processlist and show full processlist

mysql database online to troubleshoot problems, often used show processlist and show full processlist two commands

     The output processlist command shows which threads are running, not only can view all of the current number of connections, you can also view the current connection status to help identify problematic queries and so on.

If the root account, you can see all currently connected users. If other common account, you can only see their occupancy connection. showprocesslist only lists the current 100. If you want to list all, you can use SHOW FULL PROCESSLIST command

 

The meaning of each column:

1, id column, when the user logs mysql, the system assigns the "connection_id", The connection_id can use the function () View
2, user column shows the current user. If not root, this command will only display the user purview sql statement
3, host column, this statement is displayed from which ip port on which the hair can be used to track user problems arise statement
4, db column, show this which process is currently connected to a database
5, command column, the underlying command for the current connection, the general value of dormant (sleep), query (query), connect (connect), etc.
6, time column, this status display duration in seconds
7, state columns show the use of the sql statement for the current connection status, it is important columns. state describes a state statement execution. A sql statement to query, for example, may need to go through copying to tmp table, sorting result, sending data and other state before they can complete
8, info columns show the sql statement is an important basis for judging the problem statement, the general record is statement thread of execution. The default display only the first 100 characters, that is, you see the statement may be truncated, and look at all the information, use show full processlist.

 

    Remarks:

          1, according to an IP packet client to view the number of links each client's situation

     select client_ip, count (client_ip) as client_num from ( select substring_index(host, ':' ,1) as client_ip from information_schema.processlist ) as connect_info group by client_ip order by client_num desc ;
         2. Check the executing thread, according to Time Reverse Order, to see if there is not a particularly long time thread execution
      select * from information_schema.processlist where Command != 'Sleep' order by Time desc ;
         3, find all execution threads for more than 1 minute, spell out the kill statement string, easy to plug the process behind the killing
      select concat( 'kill ' , id, ';' ) from information_schema.processlist where Command != 'Sleep' and Time > 60 order by Time desc ;

         

Guess you like

Origin www.cnblogs.com/xuzhujack/p/12324610.html