What is General Query Log in MariaDB and How to Enable Query Logging in MariaDB

What is General Query Log in MariaDB 

  • The general query log is a log of every SQL query received from a client, as well as each client connect and disconnect.
  • As it keep the records of every query it grows very fast
  • If you only are intereted to keep the records for query for data change, you might want to use binary log.
  • By defaul the general query log is disabled
  • if you want to Enable it , you have to add two entries in config file.

How to Enable General Log in MariaDB

For Stand Alone MariaDB Installation go to /etc/my.cnf and add below entries
general_log =1

For Galera Cluster MariaDB Installation, go to /etc/my.cnf.d/server.cnf file and add below

general_log =1

How to Check Current values for General Query Log 

Login to MariaDB and execute below queries to check if query log is enabled and where the log file is located.

MariaDB [(none)]>  SHOW VARIABLES LIKE 'general_log';
MariaDB [(none)]>  SHOW VARIABLES LIKE 'general_log_file';

Enable General Log for Table :

To write logs into tables, the log_output server system variable is used. Allowed values are FILE, TABLE and NONE. It is possible to specify multiple values, separated with commas, to write the logs into both tables and files. NONE disables logging and has precedence over the other values.

MariaDB [(none)]>  SET GLOBAL log_output = 'FILE,TABLE';

 If General log is active for table, you can query the table to see the information.

MariaDB [(none)]>  SELECT * FROM mysql.general_log;

Check Demo video: How to enable General Query log in MariaDB

1 comment: