The general query log exposes every statement that reaches MySQL or MariaDB, which makes it useful when application behavior is unclear, unexplained writes need tracing, or a noisy client has to be identified quickly.
The server writes a general-log entry when a client connects, disconnects, or sends a SQL statement. Runtime control comes from general_log, general_log_file, and log_output, and the log records statements as they are received rather than when a transaction is committed, so it captures reads and other client activity that never appears in the binary log.
The general query log is disabled by default because it grows fast and can capture sensitive SQL text. The example below uses /var/lib/mysql/general-query.log/ for a short diagnostic window because that path is writable in default MySQL and MariaDB installs, while custom locations under /var/log/ often need directory ownership changes and sometimes AppArmor or SELinux policy updates. Recent MariaDB packages may expose the client as mariadb instead of mysql, but the SQL is the same in either client.
Quick reference: general_log=ON enables capture, log_output=FILE writes to general_log_file, log_output=TABLE writes to mysql.general_log, log_output=FILE,TABLE writes to both, and NONE suppresses query output even when general_log=ON.
$ mysql --table -u root -p -e "SHOW VARIABLES WHERE Variable_name IN ('datadir','general_log','general_log_file','log_output');" Enter password: +------------------+---------------------------------+ | Variable_name | Value | +------------------+---------------------------------+ | datadir | /var/lib/mysql/ | | general_log | OFF | | general_log_file | db01.log | | log_output | FILE | +------------------+---------------------------------+
On MariaDB the default general_log_file often appears as a relative name like db01.log instead of an absolute path. If that happens, treat it as /var/lib/mysql/db01.log/ when datadir=/var/lib/mysql/. Socket-auth installs often support
sudo mysql
or
sudo mariadb
instead of -u root -p.
$ mysql --table -u root -p -e "SET GLOBAL log_output='FILE'; SET GLOBAL general_log_file='/var/lib/mysql/general-query.log'; SET GLOBAL general_log='ON'; SHOW VARIABLES WHERE Variable_name IN ('general_log','general_log_file','log_output');" Enter password: +------------------+----------------------------------+ | Variable_name | Value | +------------------+----------------------------------+ | general_log | ON | | general_log_file | /var/lib/mysql/general-query.log | | log_output | FILE | +------------------+----------------------------------+
Use a path under the current database log or data directories unless the custom destination has already been prepared for the mysql service account. If datadir is not /var/lib/mysql/ on the host, replace the example path with one under the actual data directory or an existing writable log directory.
$ mysql -u root -p -e "SELECT NOW() AS log_marker;" Enter password: log_marker 2026-04-09 14:57:38
$ sudo tail -n 20 /var/lib/mysql/general-query.log /usr/sbin/mysqld, Version: 8.4.8 (MySQL Community Server - GPL). started with: Tcp port: 3306 Unix socket: /var/run/mysqld/mysqld.sock Time Id Command Argument 2026-04-09T14:57:38.925734Z 9 Query SELECT NOW() AS log_marker 2026-04-09T14:57:38.925957Z 9 Quit
The header and timestamp format differ by product and version. MariaDB often shows a mariadbd banner and timestamps such as 260409 14:57:38, but the decisive check is the presence of the test query in the final Argument column.
$ mysql --table -u root -p -e "SET GLOBAL general_log='OFF'; SHOW VARIABLES LIKE 'general_log';" Enter password: +---------------+-------+ | Variable_name | Value | +---------------+-------+ | general_log | OFF | +---------------+-------+
Leaving general_log=ON on a busy server can consume disk quickly and expose sensitive statement text in the log file.
[mysqld] log_output = FILE general_log = ON general_log_file = /var/lib/mysql/general-query.log
On package-managed MariaDB hosts, /etc/mysql/mariadb.conf.d/ is also a common include directory. If the log file is moved under /var/log/, create the directory first, grant it to the mysql user, and update logrotate before restarting the service.
$ sudo systemctl restart mysql
Substitute
mariadb
when the server unit is named mariadb, or restart the container or service wrapper used by the deployment.
$ mysql --table -u root -p -e "SHOW VARIABLES WHERE Variable_name IN ('general_log','general_log_file','log_output');" Enter password: +------------------+----------------------------------+ | Variable_name | Value | +------------------+----------------------------------+ | general_log | ON | | general_log_file | /var/lib/mysql/general-query.log | | log_output | FILE | +------------------+----------------------------------+