Monitor SQL statement execution efficiency based on mysql slow logs

Source: Internet
Author: User

Monitor SQL statement execution efficiency based on mysql slow logs

Enable MySQL log-slow-queries (slow query records ).

In Linux, find my. cnf file (usually in/etc/mysql/), and you may find that the file cannot be saved after modification, because you do not have the corresponding permissions, you can see from the attribute that the owner of the file is root. In this case, you must first open the file as root:

Sudo nautilus/etc/mysql

Then open the my. cnf file and find the [mysqld] Tag added below:

Log-slow-queries =/path/slow. log-slow log storage path, which is created by yourself
Long_query_time = 2-queries over 2 seconds
Log-queries-not-using-indexes-the query records do not use indexes

Save and close. If you restart MySQL, the following message is displayed: world-writable config file 'etc my. cnf 'is ignored.

Then you need to run the code again:

Chmod 644/etc/my. cnf-644 indicates rw-r-

Then restart the service.

Note: log-slow-queries =/path/slow. log is the place where slow query logs are stored. This directory requires the write permission of the MySQL running account. Generally, this directory is set to the MySQL data storage directory.

I did this: first use the root user to enter the MySQL data storage directory (usually/var/lib/mysql) and create a new slow. log File (the root user can ensure that he has the permission to create a new file and then run chmod 644 ). Then change the owner and group of the file:

Chown mysql Running Account Name (you can see the owner and group of other files in the same folder) + decimal point + group name (same user name in the method)/path/slow. log

Or:

Chown mysql Running Account Name (you can see the owner and group of other files in the same folder)/path/slow. log

Chgrp group name (same method as user name)/path/slow. log

In this way, MySQL can write logs to slow. 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.