How can I enable MySQL slow query log on my server?
mysql
Solution
Enabling slow query log has nothing to do with PHP version. You have to enable it in the MySQL server. You can enable in two ways
- In runtime
- During the server start
If your server is above 5.1.6 you can set the slow query log in the runtime itself. For which you have to execute this queries.
set global log_slow_queries = 1;
set global slow_query_log_file = <some file name>;
Or alternatively you can set the this options in the my.cnf/my.ini option files
log_slow_queries = 1;
slow_query_log_file = <some file name>;
Where the option file is changed, the MySQL server need to be restarted.
Location of the mysql option file can be found here http://dev.mysql.com/doc/refman/4.1/en/mysql-config-wizard-file-location.html
FYI : `log_slow_queries` was removed in MySQL 5.6.1 and `slow_query_log` is used instead. http://dev.mysql.com/doc/refman/5.6/en/server-options.html#option_mysqld_log-slow-queries
But for performance you can set the log output (option `log_output`) to `TABLE`. Also you can have a look other slow query log options like `long_query_time`, `log-queries-not-using-indexes`
Problem
How do I enable slow query log on my server? I have enabled it on my local host by adding `log-slow-queries =[path]` in `my.ini` file, but don't know how to add this on my server. My server is Linux-based and has PHP version 5.2.16.