Enabling the general query log makes it possible to see exactly which SQL statements reach a MySQL or MariaDB server, which helps when tracing unexpected writes, debugging application behavior, or identifying noisy clients during an incident.

The general query log records every client connect/disconnect event and every statement received by the server, and it can be toggled at runtime using the global system variables general_log and general_log_file along with log_output to select destinations such as FILE or TABLE.

Because this log grows quickly and can add significant I/O overhead, it is typically enabled only for short diagnostic windows and then disabled again, and the log location should be protected because captured statements can contain sensitive data. MySQL rewrites passwords in logged statements by default, and starting with --log-raw can suppress rewriting, which is generally unsafe for production diagnostics.

Quick reference: log_output=FILE writes to general_log_file, log_output=TABLE writes to mysql.general_log, and log_output=NONE writes no queries even when general_log=ON.

Steps to enable the general query log:

  1. Create a writable log directory for the database service.
    $ sudo install --directory --owner=mysql --group=mysql --mode=0750 /var/log/mysql

    Keep the log under a standard logging directory to simplify access control and rotation.

  2. Create the general query log file with restrictive permissions.
    $ sudo install --owner=mysql --group=mysql --mode=0640 /dev/null /var/log/mysql/general.log

    Placing the log in a non-standard directory can be blocked by AppArmor or SELinux, preventing writes without an obvious error in the log file.

  3. Open an administrative MySQL or MariaDB client session.
    $ sudo mysql
    ##### snipped #####
    mysql>

    On password-based setups, use

    mysql -u root -p

    instead of

    sudo mysql

    .

  4. Confirm the current general log settings before changing anything.
    mysql> SHOW VARIABLES WHERE Variable_name IN ('general_log','general_log_file','log_output');
    +------------------+----------------------+
    | Variable_name    | Value                |
    +------------------+----------------------+
    | general_log      | OFF                  |
    | general_log_file | host_name.log        |
    | log_output       | FILE                 |
    +------------------+----------------------+
    3 rows in set (0.00 sec)
  5. Select file output for the general query log.
    mysql> SET GLOBAL log_output = 'FILE';
    Query OK, 0 rows affected (0.00 sec)

    File output is the most practical choice for short captures because it can be inspected with standard tools like tail.

  6. Point the general query log at an absolute file path.
    mysql> SET GLOBAL general_log_file = '/var/log/mysql/general.log';
    Query OK, 0 rows affected (0.00 sec)

    If general_log_file is not set, the default is typically host_name.log under the data directory.

  7. Enable the general query log globally.
    mysql> SET GLOBAL general_log = 'ON';
    Query OK, 0 rows affected (0.00 sec)

    Leaving general_log=ON for long periods can fill disks quickly and degrade performance.

  8. Execute a small, recognizable test query to create a clear marker in the log.
    mysql> SELECT NOW() AS log_marker;
    +---------------------+
    | log_marker          |
    +---------------------+
    | 2025-12-12 22:13:49 |
    +---------------------+
    1 row in set (0.00 sec)
  9. Verify log activity by reading the most recent lines from the log file.
    $ sudo tail --lines=20 /var/log/mysql/general.log
    2025-12-12T22:13:42.911275Z	  9 Connect	root@localhost on  using Socket
    2025-12-12T22:13:49.004128Z	  9 Query	SELECT NOW() AS log_marker
    2025-12-12T22:13:55.117903Z	  9 Quit	

    When no queries appear, re-check log_output for FILE and confirm that the database service user can write to /var/log/mysql/general.log/.

  10. Disable the general query log immediately after the capture window ends.
    mysql> SET GLOBAL general_log = 'OFF';
    Query OK, 0 rows affected (0.00 sec)
  11. Persist general query log enablement in the server option file when startup logging is required.
    $ sudoedit /etc/mysql/mysql.conf.d/mysqld.cnf
    $ sudoedit /etc/mysql/mariadb.conf.d/50-server.cnf

    Startup enablement is rarely appropriate outside controlled diagnostics because logging starts immediately on server boot.

  12. Add the general query log settings under the [mysqld] section.
    [mysqld]
    general_log = ON
    log_output = FILE
    general_log_file = /var/log/mysql/general.log
  13. Restart the database service to apply option-file changes.
    $ sudo systemctl restart mysql
    $ sudo systemctl restart mariadb

    Use the unit name present on the host.

  14. Verify the global variables after restart to confirm the desired startup state.
    $ sudo mysql -e "SHOW VARIABLES WHERE Variable_name IN ('general_log','general_log_file','log_output');"
    +------------------+----------------------------+
    | Variable_name    | Value                      |
    +------------------+----------------------------+
    | general_log      | ON                         |
    | general_log_file | /var/log/mysql/general.log |
    | log_output       | FILE                       |
    +------------------+----------------------------+
Discuss the article:

Comment anonymously. Login not required.