Search code examples
phpmysqlmysql-slow-query-log

My.cnf file on Mac Sierra for Slow Queries


I am trying to set the time for my slow_query_log but I cannot find the right file:

I got a file under /usr/local/var/mysql

MYUSER-slow.log

which shows me the queries taking 10seconds (standard in MYSQL is 10sec) - I edited the my-default.cnf under /usr/local/Cellar/mysql/5.7.17/support-files/ and also added this after creating /etc/my.cnf

slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-queries.log
long_query_time = 1

Nothing seems to work tho. Who can I set the query time top 1 sec?


Solution

  • After editing the my.cnf, you need to restart mysqld to have it take effect. The configuration file is read only during startup of mysqld.

    You can also set those variables dynamically. Dynamic global variables can be changed while mysqld is running, and the change affects any subsequent sessions (current sessions don't inherit global changes).

    mysql> SET GLOBAL slow_query_log = 1;
    mysql> SET GLOBAL slow_query_log_file = /var/log/mysql/slow-queries.log;
    mysql> SET GLOBAL long_query_time = 1;
    

    Not all global variables support dynamic changes, some require a restart. This is documented per variable at https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html