mysql-Slow Query log

Source: Internet
Author: User

1 Slow query definition

means that MySQL logs all SQL statements that execute a time threshold that exceeds the Long_query_time parameter setting. The slow query log is the log that logs these SQL.

2 Turn on slow query log

Locate the MySQL configuration file my.cnf. Add below Mysqld

Log-slow-queries = D:/mysql/log/mysqld-slow-query.log  #日志存在的位置. (Note the permissions of the problem, can not set, the system will give a default file Host_name-slow.log) Long-query-time = 5   #SQL执行时间阈值, the default is 10 seconds. The #log-long-format   #说log-long-format option is used to format the log, which is an extended record of the event. The extension can record information about who issued the query and when the query was issued. Allows us to better understand the operation of the client. #log-slow-admin-statements  #将慢管理语句例如OPTIMIZE table, ANALYZE table, and ALTER TABLE are logged in the slow query log. Log-queries-not-using-indexes #如果运行的SQL语句没有使用索引, the MySQL database will also log this SQL statement to the slow query log file.

Restart the MySQL service when the configuration is complete.

3 Testing

For convenience I only configured the path of the slow query log in MY.CNF.

MySQL version is 5.1.73

about Long_query_time: starting with MySQL 5.1, Long_query_time began to record the SQL statement run time in microseconds, previously recorded only in seconds. This allows for more accurate logging of SQL uptime for DBA analysis.

into MySQL.

Mysql> show VARIABLES like "%slow%"; #查看慢查询日志相关的信息

mysql> set global long_query_time=0.01; #将mysql位置的值改为 0.01

Mysql> Show variables like "Long_query_time"; #查看是否生效

Mysql> Select Sleep (2); #延迟2秒执行 Note: This SQL execution should have generated the relevant information record in the log file of the slow query.

Mysql> show global status like '%slow% '; #查看慢查询语句的次数

You can see that SQL has been logged in the log file.

mysql-Slow Query log

Related Article

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.