Search Our Database

How To Enable MySQL Query Log on Linux Server

Last updated on |
by

Introduction

Enabling the MySQL query log is essential for troubleshooting as it allows you to backtrack your code and steps. If you’re using a control panel like DirectAdmin or cPanel, the MySQL log is typically enabled by default.

If the log is not enabled, you will need to edit your MySQL configuration file.

 

Prerequisite

  • SSH access to server
  • Basic knowledge on Linux command

 

Verify if the Log is Enabled

  1. Log in to your server via SSH.
  2. Check the MySQL configuration file by running the following command:
    cat /etc/my.cnf

    If the log is enabled, you should see a line similar to the following. The file path following the ‘=’ sign shows the location of the log file:

    log=/var/lib/mysql/mysql.log

Enable the Log

  1. Log in to your web server via SSH.
  2. Edit your MySQL configuration file by running the following commands:
    vi /etc/my.cnf

    Add this line:

    log=/var/lib/mysql/mysql.log

    Press ‘ESC’ then enter ‘:wq’ to save

  3. Restart your MySQL service:
    /etc/init.d/mysqld restart

     

Using the Query Log

You can use commands such as the tail command to trace your code and steps from the log file:

tail -f /var/lib/mysql/mysql.log

After troubleshooting, you may choose to disable the log. Note that the log file may grow over time and consume significant space on your web server.

 

Conclusion

By going through this guidance, you will be able to view your mysql log for troubleshooting and other purpose.

 

For additional assistance or if you encounter any issues, please contact our support team at support@ipserverone.com.