Monitoring SQL statement execution efficiency based on MySQL slow log
Enable MySQL log-slow-queries (slow query record).
In the Linux environment to find the My.cnf file (generally in/etc/mysql/), and then you may find that the file can not be saved after the modification, because you do not have the appropriate permissions, you can see from the properties of the file owner is root, then the first to open it as root:
sudo nautilus/etc/mysql
Then open the My.cnf file and find the [mysqld] tab and add the following:
log-slow-queries=/path/slow.log– Slow Log save path, the file itself new
long_query_time=2– query for more than 2 seconds
log-queries-not-using-indexes– record queries that do not use indexes
Save, close. Then, if you restart MySQL, you'll get the hint: world-writable config file ' etc my.cnf ' is ignored
Then you need to run this code again:
chmod 644/etc/my.cnf–644 says rw-r–r–
And then restart the service OK.
But note: Log-slow-queries=/path/slow.log for the slow query log storage place, and this directory to have the MySQL running account can write permissions, the directory is generally set to MySQL data storage directory.
I do this: first use the root user into the MySQL data storage directory (typically/var/lib/mysql), create a new Slow.log file (root users can be guaranteed to create new, and then run chmod 644). Then change the owner and the group of the file:
Chown the name of the MySQL running account (you can see the owner and group of other files in the same folder) + decimal + Group name (method with user name)/path/slow.log
Or:
Chown the name of the MySQL run account (you can see the owner and group of other files in the same folder)/path/slow.log
CHGRP group name (method with user name)/path/slow.log
This ensures that MySQL can write logs to Slow.log.
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.