Turn on the general log in MySQL?


To turn ON the general log, you need to use SET command.

 Following is the syntax −

set global general_log=ON;

Let us check the general log status with the help of SHOW command −

mysql> SHOW variables like '%general_log%';

This will produce the following output −

+------------------+---------------------+
| Variable_name    | Value               |
+------------------+---------------------+
| general_log      | OFF                 |
| general_log_file | DESKTOP-QN2RB3H.log |
+------------------+---------------------+
2 rows in set (0.06 sec)

Following is the query to turn on the general log −

mysql> set global general_log=ON;
Query OK, 0 rows affected (0.18 sec)

Let us check the status of general log once again −

mysql> SHOW variables like '%general_log%';

This will produce the following output −

+------------------+---------------------+
| Variable_name    | Value               |
+------------------+---------------------+
| general_log      | ON                  |
| general_log_file | DESKTOP-QN2RB3H.log |
+------------------+---------------------+
2 rows in set (0.01 sec)

You can change the location of general_log_file −

mysql> SET GLOBAL general_log_file = 'E:\mysqllog';
Query OK, 0 rows affected (0.11 sec)

Let us check the status of general_log_file once again −

mysql> SHOW variables like '%general_log%';

This will produce the following output −

+------------------+------------+
| Variable_name    | Value      |
+------------------+------------+
| general_log      | ON         |
| general_log_file | E:mysqllog |
+------------------+------------+
2 rows in set (0.01 sec)

Updated on: 30-Jul-2019

724 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements