Software >> Services >> RDBMS >> MySQL >>  How to enable mysql error and query log

edit /etc/my.cnf

at the section on mysqld, add following line

log-error=path-to-error-log

then restart mysql

# /etc/init.d/mysql stop
# /etc/init.d/mysql start


## To enable at runtime, use SET GLOBAL statement to set the respective variable e.g. for query log

MariaDB [(none)]> SET GLOBAL general_log='ON';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SET GLOBAL general_log_file='/var/log/mariadb/mariadb-error.log';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show variables like 'general_log%';
+------------------+----------------------------------+
| Variable_name    | Value                            |
+------------------+----------------------------------+
| general_log      | ON                               |
| general_log_file | /var/log/mariadb/mysql-query.log |
+------------------+----------------------------------+
2 rows in set (0.00 sec)