Powered by Blogger.

How and When To Enable MySQL Logs

Here is a simple way to enable them. In mysql we need to see often 3 logs which are mostly needed during any project development.
  • The Error Log. It contains information about errors that occur while the server is running (also server start and stop)
  • The General Query Log. This is a general record of what mysqld is doing (connect, disconnect, queries)
  • The Slow Query Log. Ιt consists of "slow" SQL statements (as indicated by its name).
By default no log files are enabled in MYSQL. All errors will be shown in the syslog.(/var/log/syslog)
To Enable them just follow below steps
step1: Go to this file(/etc/mysql/conf.d/mysqld_safe_syslog.cnf) and remove or comment those line.
step2: Go to mysql conf file(/etc/mysql/my.cnf ) and add following lines
To enable error log add following

To enable general query log add following
general_log_file        = /var/log/mysql/mysql.log
general_log             = 1
To enable Slow Query Log add following
log_slow_queries       = /var/log/mysql/mysql-slow.log
long_query_time = 2
step3: save the file and restart mysql using following commands
service mysql restart
To enable logs at runtime, login to mysql client (mysql -u root -p ) and give:
SET GLOBAL general_log = 'ON';
SET GLOBAL slow_query_log = 'ON';
Finally one thing I would like to mention here is I read this from a blog. Thanks. It works for me.
    Blogger Comment
    Facebook Comment