Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

How can I enable MySQL's slow query log without restarting MySQL?

I followed the instructions here: http://crazytoon.com/2007/07/23/mysql-changing-runtime-variables-with-out-restarting-mysql-server/ but that seems to only set the threshold.

Do I need to do anything else like set the filepath?

According to MySQL's docs

If no file_name value is given for --log-slow-queries, the default name is 
host_name-slow.log. The server creates the file in the data directory unless 
an absolute path name is given to specify a different directory. 

Running

SHOW VARIABLES

doesn't indicate any log file path and I don't see any slow query log file on my server...

EDIT

Looks like I'm using server version 5.0.77, so I needed to do:

SET GLOBAL log_slow_queries = 1;

but I get: ERROR 1238 (HY000): Variable 'log_slow_queries' is a read only variable

I assume I'm going to need to restart the server and have log_slow_queries set in my config?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try SET GLOBAL slow_query_log = 'ON'; and perhaps FLUSH LOGS;

This assumes you are using MySQL 5.1 or later. If you are using an earlier version, you'll need to restart the server. This is documented in the MySQL Manual. You can configure the log either in the config file or on the command line.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...