How to enable the MySQL slow query log and analyze it

Follow

Comments

2 comments

  • Avatar
    Marcos Martinez

    Hi, 

    after doing the configuration, I get the following error from Mariadb.log  "Could not use /var/log/mysql-slow.log for logging (error 13). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.  plesk".

    I think this error is about permission, but how can I grant permission to  a mysql user over the "mysql-slow.log" file?

    Thanks in advance, 

    Regards.

  • Avatar
    Alexandr Redikultsev

    Hello, @Marcos Martinez.

    Basically doing the following chown should be enough to provide mysql user access to mysql-slow.log file:

    # chown mysql:mysql /var/log/mysql-slow.log

    However, I can imagine the situation when there are some limitations applied by the operation system.

    I suggest the following action plan to troubleshoot the issue:

    1. Try creating the file in the same directory where the initial error log of MySQL is located on the server. You can find it with the following command:

    # grep -R 'log-error' /etc/my*
    /etc/my.cnf:log-error=/var/log/mariadb/mariadb.log

    In my example, I would create a file in /var/log/mariadb/mysql-slow.log.

    2. Adjust the steps in the article to use /var/log/mariadb/mysql-slow.log (or the other path that you will be using).

    3. Verify that log-slow-queries as well as all the other related directives in my.cnf are indeed under [mysqld] section and not under [mysqld_safe].

    4. Do not forget to execute chown on the file:

    # chown mysql:mysql  /var/log/mariadb/mysql-slow.log 

Please sign in to leave a comment.

Have more questions? Submit a request