These steps explain how to enable MySQL Slow Query Logging on VPS and Dedicated Servers. This is useful for troubleshooting MySQL database issues as well as load issues on the server related to MySQL. Root access and SSH access will be needed to complete these steps.
Enable Slow Query Logging
IMPORTANT: This solution will require root access. If this needs to be obtained, follow the guide on requesting root access.
- SSH into the appropriate server as root
- Create the log file
touch /var/log/slowqueries
- Update file ownership for /var/log/slowqueries to be owned by the mysql user
chown mysql:mysql /var/log/slowqueries
- Update file permission for /var/log/slowqueries
chmod 664 /var/log/slowqueries
- Using your favorite text editor, edit the MySQL config file at the path below
/etc/my.cnf
- Now add the lines below to the bottom of the my.cnf file
slow_query_log = 1 slow_query_log_file = /var/log/slowqueries long_query_time = 3
- Restart MySQL for slow query logging to begin
service mysql restart
NOTE: At this time, MySQL should start writing to the file /var/log/slowqueries. Its always recommended to check/cat the file /var/log/slowqueries to ensure that its being populated.
Comments
0 comments
Article is closed for comments.