Thứ Ba, 10 tháng 9, 2013

How to log MySQL slow queries

Since I upgraded mywebsite to VPS, I can analyse the slow queries by loggin them into a file without restarting mysql as follows:

# touch /var/log/slow
# chown mysql:mysql /var/log/slowqueries
# mysql -e 'SET GLOBAL slow_query_log=1;'
# mysql -e 'SET GLOBAL slow_query_log_file="/var/log/slowqueries";'
# mysql -e 'SET GLOBAL long_query_time=5;'

Or I can add these lines to my.cnf:
slow_query_log=1
slow_query_log_file=/var/log/slowqueries
long_query_time=2

To test if it is working correctly, try:
# mysql -e 'SELECT SLEEP(6);'

Không có nhận xét nào:

Đăng nhận xét