mysql database slow SQL troubleshooting

Purpose: Record the sql query over 200ms for statistics, and optimize the corresponding results based on the results.

By default, the MySQL database does not start the slow query log, and you need to manually enable the configuration. If it is not required for tuning, it is generally not recommended to enable this parameter, because turning on the slow query log will more or less bring about a certain performance impact.

Manipulation: open configuration

1. Whether slow sql query is enabled

SHOW VARIABLES LIKE'log_slow_queries'; Turn ON OFF OFF Default is OFF

2. View the slow sql statistics time

show variables like'%long_query_time%' default 10.0000 sql statistics greater than 10 seconds

3. Is the slow sql query log enabled?

show variables like'%slow_query_log%'; turn ON, turn OFF, default is OFF

4. View the slow sql log location

show variables like'%slow_query_log_file%' folder location

5. Turn on slow sql query

set global slow_query_log=1

6. Set slow sql query statistics time

set global long_query_time=0.2 set to 200ms

After completing the above content, wait for a period of time, go to the designated log location to view the log file, through the log file, you can use slow SQL analysis software or explain to analyze the slow SQL to achieve the final optimization.

 

 

 

Guess you like

Origin blog.csdn.net/A___B___C/article/details/107747253