Mysql slow query log process mysql slow query log is very useful for tracking problematic queries, you can analyze the resource-consuming SQL statements in code implementation, there is a high reference for our program optimization. This article
1. The configuration is enabled.Linux: In the mysql configuration file my. add log-slow-queries =/var/lib/mysql/slowquery in cnf. log (specify the location where the log file is stored, which can be null, the system will give a default file
How to enable slow query in MySQL
1. The configuration is enabled.
Linux:
Add
Log-Slow-queries =/var/lib/MySQL/slowquery. Log (specify the location where the log file is stored, which can be empty and the system will give a default file
The online business uses the ORM framework, and discovers a slow query SQL that has been sorted two times in the same field, resulting in filesort. The ORM Framework has its own table structure as follows:
CREATE TABLE ' Unopen ' ( ' Corp '
MySQL has a function is log down to run the slower SQL statement, the default is not this log, in order to open this function, to modify the my.cnf or in the MySQL boot when the add some parameters. If you modify inside the MY.CNF, add the following
Slow queryWe know that the general application system, MySQL read and write ratio of about 10:1, and the general insert and update operations rarely appear performance problems, encountered the most problems, but also the most prone to problems, or
When the system performance reaches the bottleneck, it is necessary to find out those operations on the performance impact of the system is relatively large, here you can use the database slow query log function to record some more time-consuming
The slow query log feature is not turned on by default, and it records a value that executes longer than the parameter Long_query_time (default is 10) and the number of rows accessed exceeds the SQL statement that the parameter
Reference: 5 kinds of MySQL log analysis tools to compete http://blog.csdn.net/gzh0222/article/details/103844751.mysql-log-filter Tool Script Usage instructions:An analysis tool found on Google code. Two executable scripts for Python and PHP are
Slow queries need to be optimized for normal workYou have to use Percona-tookit's pt-query-digest to analyze slow logs.Percona-tookit:Https://www.percona.com/doc/percona-toolkit/3.0/index.htmlHow to use:#pt-query-digest Slow log filesThe summary of
MySQL Slow query:Check if log on slow query is turned on:
Show variables like ' log_slow_queries ';
View SQL that is slower than how many seconds are logged to the log file:
Show variables like ' long_query_time ';
Configure Logging
Command: Show Processlist;If it is the root account, you can see the current connection for all users. If you are a normal account, you can only see the connection you are occupying.Show Processlist; only the first 100 are listed, please use show
One: Query the status of slow log, as shown in the sample code, slow log is already open.Mysql>Show variables like '%slow%';+---------------------+------------------------------------------+|Variable_name|Value|+---------------------+----------------
How do I turn on the slow query log?Added in MySQL config file my.cnfLog-slow-queries=/var/lib/mysql/slowquery.log (Specify the log file location, can be empty, the system will give a default file Host_name-slow.log)long_query_time=2 (record over
1 in MySQL, the default is not to turn on the slow query log function, we can use show variables like '%slow% ' to see. The results are as follows:650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/26/EA/wKiom1NuKfvDr8nqAAFYiGubJfQ397.jpg
Open MySQL Slow query
MySQL Slow query log for tracking Php+mysql system under the MySQL load tuning problem is very useful, such as installing a lot of discuz! plug-ins users, so you can probably troubleshoot those plug-ins have code problems. In
MySQL log-slow query log (slow-query-log)Slow query log: All SQL statements that run longer than long_query_time in MySQL slow query log records help you find slow SQL statements, so that we can optimize these SQL statements. Slow query log
Mysqldumpslow:Died at/usr/local/mysql/bin/mysqldumpslow line 161, <> chunk 236.
Conclusion: The number of top jobs is too large, and mysqldumpslow cannot be traversed.
/Usr/local/mysql/bin/mysqldumpslow-s-t 15/root/db01-102-slow.log
1. Try removing
MySQL Log System details
All those who have done large systems know that the log function is not to be underestimated. In the middle and late stages of the project, the optimization and upgrade of the project are based on the log to make the upgrade
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.