MySQL slow query log and MySQL slow log

Source: Internet
Author: User
Tags mysql slow query log

MySQL slow query log and MySQL slow log

Lab environment:
OS X EI Captian + MySQL 5.7

1. Configure MySQL to automatically record slow query logs

View the variable, that is, the configuration information.

show (global) variables like '%slow_query%'

Modify variable:

Set global variable name = Value

Variables related to slow query logs:

Whether to enable the slow query log slow_query_log = OFF long_query_time = 10 maximum time limit. If the time limit is exceeded, record slow_query_log_file =/usr/slow. log File Location log_queries_not_using_indexes = OFF whether to record searches without Indexes

Enable the slow query log first:

Bytes

Modify query time:

Bytes

The remaining two global variables are the default values for log paths and records without indexes.

Ii. View MySQL slow query logs

You can directly view:

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

Bytes

You can also usemysqldumpslowView slow query logs:

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

View helpmysqldumpslow --help:

Bytes

Translation:

-- Verbose version -- debug debugging -- help-v version-d debugging mode-s ORDER sorting mode al: average lock time ar: average rows sent at: average query time default c: count l: lock time r: rows sent t: query time-r reverse order. The default reverse order of the file-t NUM shows the first N-a. Do not convert the number in SQL to N, converting string to S-l in total time does not subtract lock time

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.