Skip to content

Instantly share code, notes, and snippets.

@ssavva05
Forked from joseluisq/mysql_query_log.md
Last active April 29, 2020 10:39
Show Gist options
  • Save ssavva05/6bc1e47bae97a9afa01a9a08fcb7fea2 to your computer and use it in GitHub Desktop.
Save ssavva05/6bc1e47bae97a9afa01a9a08fcb7fea2 to your computer and use it in GitHub Desktop.
How to enable the MySQL/MariaDB general query logs

How to enable the MySQL/MariaDB general query logs

  1. Enter to MySQL/MariaDB server command-line tool (change root with your username and password):
mysql -u root -proot
  1. Set the general log file path:
SET GLOBAL general_log_file='/var/log/mysql/mycustom.log';
  1. Set the log output to file format:
SET GLOBAL log_output = 'FILE';
  1. Enable the server general log:
SET GLOBAL general_log = 'ON';
  1. Show the general log settings:
SHOW VARIABLES LIKE "general_log%";
  1. Try to execute your own SQL query from your app or command-line tool...

  2. View the general log file content:

less /var/log/mysql/mycustom.log
  1. Disable the general server log:
SET GLOBAL general_log = 'OFF';

MariaDB documentation suggests using 1 to enable logging, and 0 to disable it. So it should be:

Enable the server general log:

SET GLOBAL general_log = 1;

Disable the general server log:

SET GLOBAL general_log = 0;

Source: https://mariadb.com/kb/en/server-system-variables/#general_log

@ssavva05
Copy link
Author

MariaDB documentation suggests using 1 to enable logging, and 0 to disable it. So it should be:

Enable the server general log:
SET GLOBAL general_log = 1;
Disable the general server log:
SET GLOBAL general_log = 0;
Source: https://mariadb.com/kb/en/server-system-variables/#general_log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment