php - A website running online, how to check whether which sql statement needs optimization?
天蓬老师2017-06-05 11:07:52
0
5
686
For example, if a website is running online and it is found that a certain page loads very slowly, how to check whether which SQL statement needs to be optimized
Check the log and find the corresponding sql desc or explain select....(your sql statement) to check the efficiency, or write the execution efficiency directly to the log
In the configuration of mysql, enable slow query slow_query_log and statement without index log_queries_not_using_indexes. You can use the explain + sql statement to check the execution efficiency of sql.
You should also pay attention to whether it can be optimized in the program. Don't put database queries in loops.
Slow query log.
Check the log and find the corresponding sql desc or explain select....(your sql statement) to check the efficiency, or write the execution efficiency directly to the log
If it is Laravel, you can use debugbar https://github.com/barryvdh/l...
In the configuration of mysql, enable slow query slow_query_log and statement without index log_queries_not_using_indexes. You can use the explain + sql statement to check the execution efficiency of sql.
You should also pay attention to whether it can be optimized in the program. Don't put database queries in loops.
Have you used a framework? You can monitor the running time of each SQL. And record the logs and analyze them one by one.