Turn on MySQL slow query log

Source: Internet
Author: User
Tags mysql slow query log

To view the configuration:

View slow query time show variables like "Long_query_time"; Default 10s
View slow query configuration show status like "%slow_queries%";
View slow query log path show variables like "%slow%";

Modifying a configuration file

Add the following two words to the My.ini
Log-slow-queries = D:\wamp\mysql_slow_query.log
Long_query_time=5
The first sentence is used to define the path to the slow query log (because it is windows, so there is no permission issue involved)
The second sentence uses to define how many seconds of query is slow query, I define here is 5 seconds
Step Two: View the status of a slow query
Execute the following SQL statement to view the status of the MySQL slow query
Show variables like '%slow% ';
The execution results will print on the screen whether the slow query is turned on, the number of seconds to slow query, the slow query log, and so on.
Step three: Perform a slow query operation
In fact, it is difficult to perform a meaningful slow query, because when you test it, it only takes 0 seconds to query a huge list of 200,000 data. We can replace it with the following statement:
SELECT SLEEP (10);
Fourth step: View the number of slow queries
Use the following SQL statement to see how many slow queries have been performed:
Show global status like '%slow% ';

Configuration of MySQL logs:

Note: These days files will not be generated until MySQL restarts.
#记录所有sql语句log =e:/mysqllog/mysql.log# records the database startup shutdown information and the error messages that are generated during the run log-error=e:/mysqllog/myerror.log# Records all SQL statements except the SELECT statement into the log, which can be used to recover data files log-bin=e:/mysqllog/bin# record query slow SQL statements Log-slow-queries=e:/mysqllog/slow.log #慢查询时间long_query_time =0.5

Turn on MySQL slow query log

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.