mysql slow query

① First of all, let's understand how to query some running states of the mysql database (for example, want to know the current running time of mysql/how many times select/update/delete../current connection has been executed)

show status

common:

show status like ‘uptime’ ;

show stauts like ‘com_select’  showstauts like ‘com_insert’ ...类推 update  delete

 ☞ show [session|global] status like .... If you don't write [session|global], the default is the session session, which refers to the execution of the current window. If you want to see all (from mysql startup to now, it should be global)

 show status like ‘connections’;

// Display the number of slow queries

show status like ‘slow_queries’;

② How to locate slow query

2.1 Modify the slow query of mysql.

show variables like 'long_query_time'; //Can display the current slow query time, the default is 10 seconds, the query result is as follows


2.2set long_query_time=0.5 ;//You can modify the slow query time, and then use show variables like 'long_query_time'; query to know that the modification is successful, as shown below

2.3 There is an emp table in my data. Here I will query the statement. The time is 0.84 seconds, which is greater than the 0.5 seconds we set earlier. Then go to our Mysql my.ini file to check the location of the data storage, as shown in the following figure.

3.4 Coming to this file, we see the query slow log

3.5, open this file and see that this slow query has been recorded




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324780422&siteId=291194637