MySQL Slow query log

Source: Internet
Author: User
Tags mysql slow query log

Lab Environment:
OS X EI Captian + MySQL 5.7

I. Configure MySQL to automatically record slow query log

View variables, i.e. configuration information

show (global) variables like '%slow_query%'

To modify a variable:

set global 变量名 = 值

Variables related to the slow query log:

是否开启慢查询日志slow_query_log = OFF long_query_time = 10   最大时间限制,超过此时间,再记录slow_query_log_file = /usr/slow.log日志文件位置log_queries_not_using_indexes = OFF没有使用索引的搜索是否记录

Let's start with the slow query log:

?

Modify Query Time:

?

There are two global variables left, and log paths and records with no indexes are the default values.

Second, check the MySQL slow query log

Can be viewed directly:

vim /usr/local/var/mysql/DyanLideMacBook-Air-slow.log

?

You can also use the mysqldumpslow view slow query log:

mysqldumpslow -s at -a  /usr/local/var/mysql/DyanLideMacBook-Air-slow.log

View Help mysqldumpslow --help :

?

Translation of several commonly used:

--verbose    版本--debug      调试--help       帮助 -v           版本-d           调试模式-s ORDER     排序方式              al: average lock time              ar: average rows sent              at: average query time 默认               c: count               l: lock time               r: rows sent               t: query time-r           反转顺序,默认文件倒序拍-t NUM       显示前N条-a           不要将SQL中数字转换成N,字符串转换成S-l           总时间中不减去锁定时间

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.