In the process of operating the website, you may encounter the problem of a sudden slow web site, in general, and MySQL slow relationship, you can open the slow query , to find the efficiency of SQL , and then take appropriate measures. Here's how to turn on slow queries:
1. Turn on slow query
Locate the MySQL configuration file, my.cnf (Windows My.ini), and add the following lines under [Mysqld]:
long_query_time=2
log-slow-queries=/usr/var/slowquery.log
The above 2 is the time of the query, that is, when a SQL execution time exceeds 2 seconds to record ,/usr/var/slowquery.log is the location of the log records.
Then restart the MySQL service
Note that the MySQL 5.6 version, logging slow query log configuration has been modified to:
long_query_time=2
Slow_query_log=1
Slow_query_log_file=/tmp/slow-query.log
Additionally, a configurable record does not use the indexed query log:
Log_queries_not_using_indexes=1
2. Location of MySQL configuration files
The windows:windows configuration file is My.ini, usually under the MySQL installation directory or under C:\Windows.
Linux: Linux configuration file is my.cnf, usually in/etc.
Note: The current MySQL connection process can be viewed by mysql>show full processlist;
3. To record all operation logs, including select
Added in My.ini or my.cnf profile, [mysqld]: log= file name
Example: Log=/tmp/mysqlquery.log
Restart Mysqld, which will record all relevant operational logs
Note: Log record location, MySQL should have write permission;
Note that in MySQL version 5.6, the configuration of all operation logs is changed to:
General_log=on
General_log_file=/tmp/mysqlquery.log
mysql-turn on slow query & all operations logging