Enable or disable General Log for sql query in MySQL.

Check the General_log parameter setting in MySQL

General_log system variable controls logging to the general query log for the selected log destinations. General_log value 0 for disable or 1 for enable.
Set the general_log_file variable for specify the file location.

Check enable or disable General Log
Note: General_log value 0 for disable or 1 for enable.

mysql> SELECT @@general_log;
+---------------+
| @@general_log |
+---------------+
|             0 |
+---------------+
1 row in set (0.00 sec)

Enable or disable the general_log in MySQL

-- Enable the General Log 
mysql> SET GLOBAL general_log=1;
Query OK, 0 rows affected (0.00 sec)
OR
mysql> SET GLOBAL general_log = 'ON';

--Disable the General log 
mysql> SET GLOBAL general_log=0;
Query OK, 0 rows affected (0.00 sec)
OR
mysql> SET GLOBAL general_log = 'OFF';

Check the log location or name for general log file

Note: --On Windows:  C:\ProgramData\MySQL\MySQL Server 8.0\Data\RACDB.log

mysql> SELECT @@general_log_file;
+--------------------+
| @@general_log_file |
+--------------------+
|          RACDB.log |
+--------------------+
1 row in set (0.00 sec)

Change the location or name for general log file


-- Set the RAC DB log file
mysql> SET GLOBAL general_log_file='MYSQLGENERAL.log';
Query OK, 0 rows affected (0.02 sec)

-- Check the log 
mysql> SELECT @@general_log_file;
+--------------------+
| @@general_log_file |
+--------------------+
| MYSQLGENERAL.log   |
+--------------------+
1 row in set (0.00 sec)

log_output system variable specifies the destination for log output.
Choose value from TABLE , FILE or NONE. If you choose TABLE then check the structure of table.

SET GLOBAL log_output='FILE';

SET GLOBAL log_output='TABLE';
-- IF you set to TABLE.
SHOW CREATE TABLE mysql.general_log;
SHOW CREATE TABLE mysql.slow_log;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.