Enable Logs in MySQL

MySQL

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.

Error Log ñ this contains all the information about errors generated by MySQL server.
General Log ñ this contains all the general logs of MySQL activity like query, user connect or disconnect.
Slow Query Log ñ this contains ìslowî SQL statements, All the queries which is taking more time than expected.
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 = varlogmysqlerror.log
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 = varlogmysqlmysql.log
general_log = 1
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 = varlogmysqlmysql-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