Monday, January 14, 2013

MySQL Logs

MySQL have many types of logs which make debugging more easily...
To know logs are enabled or not we should follow this steps:
1- Login using SSH
2- Connect to mysql server: mysql -u[username] -p[password]
3- Run : mysql> show variables like '%log%';
The Result of query will be some thing like this:

+---------------------------------+---------------------------+
| Variable_name                   | Value                     |
+---------------------------------+---------------------------+
| log                             | ON                        | 
| log_bin                         | OFF                       | 
| log_bin_trust_function_creators | OFF                       | 
| log_error                       | /var/log/mysqld.error.log | 
| log_slow_queries                | OFF                       | 
+---------------------------------+---------------------------+
26 rows in set (0.00 sec)

as we see the logs are not enabled so we need to enable it using some steps:
1- open my.cnf file (may be in /etc/mysql/my.cnf)
2- find [mysqld] section and write

log-bin
log
log-error
log-slow-queries
below it.
3- save the file and restart mysql service: sudo restart mysql
The logs will be created, by default, in the same data directory that holds the database subdirectories themselves (typically /var/lib/mysql) and the log file names default to the hostname followed by a suffix that matches the directive names above (eg. -bin, -slow-queries, etc).
Sources:
1- http://dev.mysql.com/doc/refman/5.0/en/server-logs.html
2- http://serverfault.com/questions/71071/how-to-enable-mysql-logging

No comments:

Post a Comment