Search Our Database

How To Enable MySQL Query Log on Linux Server

Last updated on |
by

It is best to enable MySQL query log so that you can backtrack your codes and steps for troubleshooting purposes.
If you were using control panel like, DirectAdmin or cPanel, you may not worry on this because the log for MySql will be enabled by it.

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

To verify the if the log is enabled:
1. Login into your server via SSH.
2. Check the MySQL configuration file by running the following command.

cat /etc/my.cnf

3. If the log is enabled, you will see the line as below. The file behind ‘=’ is the path where the log located.

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

 

If is not enabled, you may follow the step below:
1. Login into your web server via SSH.
2. Edit your MySQL configuration file by running the following commands.

vi /etc/my.cnf
#add in 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

 

You can now use commands such as tail command to trace your codes and steps from the log file.

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

You may disable the log after troubleshooting. Due to, the log file may grow over time and take up space in your web server.