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.
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
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
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.
Or alternatively you can set the this options in the my.cnf/my.ini option files
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 andslow_query_log
is used instead. http://dev.mysql.com/doc/refman/5.6/en/server-options.html#option_mysqld_log-slow-queriesBut for performance you can set the log output (option
log_output
) toTABLE
. Also you can have a look other slow query log options likelong_query_time
,log-queries-not-using-indexes
First (as root:)
Then under [mysqld] in /etc/my.conf (or wherever your configuration file is:)
Next:
Finally:
Verification:
You can set it temporarily, by running the following commands:
but your changes will be undone when mysql is restarted.
You can set it permanently, by adding the following to your
my.cnf
file:The location of
my.cnf
varies by OS, but is often found in/etc/my.cnf
, or/etc/mysql/my.cnf
:After saving your changes, you will need to restart MySql. This can vary by OS, but here are some common examples:
and