How to record mysql slow query SQL log and modify mysqld section of my. cnf: long_query_time1 ????????????? 1 indicates 1 second for a slow query -- log-slow-queries [file_name]? Slow query of log files -- log-queries-not-using-indexes:
How to record mysql slow query SQL log and modify mysqld section of my. cnf: long_query_time = 1 ????????????? // Define the slow query time 1 to indicate 1 second -- log-slow-queries [= file_name]? // Record slow query to the log file -- log-queries-not-using-indexes // record SQL statements that do not use indexes to the log file instance:
How to record mysql slow query SQL logs
Modify the mysqld section of my. cnf:
Long_query_time = 1 ????????????? // Define the slow query time. 1 indicates 1 second.
-- Log-slow-queries [= file_name]? // Record slow query to log files
-- Log-queries-not-using-indexes // records SQL statements that do not use indexes to log files.
Instance:
[Mysqld]
Long_query_time = 1
Log-slow-queries =/usr/local/mysql5.0.40/var/slow_query.log
Log-queries-not-using-indexes = true
"Too connector connections" could not find the problem. Later, it was found that the slow query of mysql would be of great help.
Open MySQL slow Query
MySQL slow query record logs are useful for tracking MySQL load tuning issues in the PHP + MySQL system, such as installing a lot of Discuz! Plug-in users, so that you can probably find out which plug-ins have code problems. In fact, it is very easy to enable MySQL slow query logs. You only need to add the log-slow-queries and long_query_time parameters to the MySQL configuration file.
Today, a friend asked me to bring the record up. For more MySQL optimization information, see here: http://www.ccvita.com/category/mysql
Enable MySQL slow query in Windows
In Windows, the configuration file of MySQL is usually my. ini. Find [mysqld] and add
Log-slow-queries = F: \ MySQL \ log \ mysqlslowquery. log
Long_query_time = 2
Enable MySQL slow query in Linux
The configuration file of MySQL in Windows is usually my. cnf. Find [mysqld] and add
Log-slow-queries =/data/mysqldata/slowquery. log
Long_query_time = 2
Note:
Log-slow-queries = F: \ MySQL \ log \ mysqlslowquery. log is the location where the query log is stored. Generally, this directory requires the write permission of the MySQL running account. Generally, this directory is set to the MySQL data storage directory;
2 In long_query_time = 2 indicates that the query takes more than two seconds to record;
Enable slow log
? There are two ways to enable: 1, in my. in cnf, log-slow-queries [= file_name] 2 is used to specify the five commonly used tools compared by the -- log-slow-queries [= file_name] option when the mysqld process is started.
?
Mysqldumpslow, mysqlsla, myprofi, mysql-explain-slow-log, mysqllogfilter
Mysqldumpslow is the log analysis tool for slow query officially provided by mysql. The output chart is as follows:
What are the main functions ,? Count the occurrences of different slow SQL statements ),? Maximum execution Time (Time ),? Total Time consumed ),? Lock wait time (Lock ),? Total number of Rows sent to the client (Rows ),? Total number of Rows scanned (Rows ),? The user and the SQL statement itself (Abstract The format, for example, limit 1, 20 is represented by limit N, N ).
Here are some useful parameters :?
-S sorting option: c query times r returns the number of record rows t query time?
-T: only top n queries are displayed?
Mysqldumpslow-s r-t 10 slow. log?
?
Mysqlsla, a log analysis tool launched by hackmysql.com (This website also maintains mysqlreport, mysq1_xchk, and other useful mysql tools)
Data reports are very helpful for analyzing the causes of slow queries, including execution frequency, data volume, and query consumption.
?
? The format description is as follows: total queries (queries total), number of de-duplicated SQL statements (unique) The most important slow SQL statement statistics in sorting the output report content (sorted, including average execution time, lock wait time, total number of result rows, and total number of scanned rows.
? Count, the number of SQL executions and percentage of the total slow log Count. time, execution Time, including the total Time, average Time, minimum, maximum Time, and Time as a percentage of the total slow SQL Time. 95% of Time removes the fastest and slowest SQL statements, and the SQL Execution Time with a coverage rate of 95%. lock Time, the waiting Time. 95% of Lock, 95% of slow SQL wait Lock time. rows sent, the number of result Rows, including average, minimum, and maximum.
Rows examined, number of Rows scanned. Database, which Database is Users, user, IP address, and percentage of SQL executed by all Users
? Query abstract: abstract SQL statement Query sample, SQL statement
? In addition to the above output, the official website also provides many customized parameters, which are a rare tool.
? Mysql-explain-slow-log, a perl script written by the Germans.
Http://www.willamowius.de/mysql-tools.html
?
The function is a bit flawed, not only printing all slow logs to the screen, but also counting only the quantity. not recommended. mysql-log-filter, an analysis tool found on google code. provides two executable scripts: python and php.
Http://code.google.com/p/mysql-log-filter/
?
? Compared with the official mysqldumpslow function, the query time statistics (average, maximum, and accumulative) are added. Other functions are similar to mysqldumpslow.
In addition to statistical information, the featured features are also formatted and formatted to ensure the overall output is concise. If you like concise reports, we recommend that you use them.
Myprofi is an open-source analysis tool written in php. The project is on sourceforge.
Http://myprofi.sourceforge.net/
?
?
Function, lists the total number and type of slow queries, deduplicated SQL statements, the number of executions, and the percentage of the total number of slow logs.
The overall output style is more concise than mysql-log-filter, saving a lot of unnecessary content. It is recommended for users who only want to view SQL statements and the number of executions.
?
Tools/functions |
General Statistics |
Advanced Statistics |
Script |
Advantages |
Mysqldumpslow |
Supported |
Not Supported |
Perl |
Official mysql built-in |
Mysqlsla |
Supported |
Supported |
Perl |
Powerful functions, complete data reports, and strong customization capabilities. |
Mysql-explain-slow-log |
Supported |
Not Supported |
Perl |
None |
Mysql-log-filter |
Supported |
Partially supported |
Python or php |
Keep the output concise without losing its functionality |
Myprofi |
Supported |
Not Supported |
Php |
Excellent |