Logs are very useful part of any service to check status. We can easily trouble shoot issues using logs data. In this article you will know how to enable different types of logs in MySQL server or change log file location in MySQL server.

  • General Log – this contains all the general logs of MySQL activity like query, user connect or disconnect.
  • Error Log – this contains all the information about errors generated by MySQL server.
  • Slow Query Log – this contains “slow” SQL statements, All the queries which is taking more time than expected.

General Log:

To enable general logs in MySQL or to change location of general log files, edit configuration file and make following changes. Uncomment following lines to enable general logs and change log file path to create log on different directory. This file contains all general logs of mysql server for eg: queries, user connect or disconnect etc.

 general_log_file   = /var/log/mysql/mysql.log
 general_log        = 1

Error Log:

To Enable MySQL error log or change MySQL error log location. Edit MySQL configuration file and update following setting under [mysqld] as per your requirements. This file contains error generated in MySQL server.

 [mysqld]
 log_error = /var/log/mysql/error.log

Slow Query Log:

To enable or change file path of MySQL slow query logs. Edit MySQL configuration file and uncomment or add following line in [mysqld] section. This file contains logs of those queries which is taking more time to complete. Which queries taking time more than defined as long_query_time are logged.

 log_slow_queries       = /var/log/mysql/mysql-slow.log
 long_query_time 	= 2

Restart MySQL:

After making above changes, you are required to restart MySQL services. Use one of following command as per your operating system.
This method requires a server restart.

# service mysql restart

[or]

# systemctl restart mysql.service