MariaDB Store General Query Log in database
Last updated: May 29, 2022
Colleagues hello to all.
In today's article, we'll continue talking about the General Query Log in MariaDB. In the last article, we talked about how to store all sql queries that come from the client in a file, and today we will look at how to store the query log in the database.
- Variable log_output.
- Clear log.
1. log_output variable.
In a MariaDB database, the log_output variable is responsible for storing the overall query log. By default, it stores FILE values, which means that all requests that come from the client will be stored in a regular file.
mariadb> SHOW VARIABLES LIKE 'log_output';
The log_output variable is dynamic, so we can change its value with the SET GLOBAL command.
mariadb> SET GLOBAL log_output = 'TABLE';
And of course, add the variable to the configuration file.
All logs will be written to the mysql.general_log table.
2. Clearing the log.
In MariaDB, unfortunately there is no such command to clean up the table automatically, so you will have to do the cleaning yourself. Although you can make a function and put it on the task scheduler.
mariadb> truncate table mysql.general_log;
Thank you all, I hope that my article helped you in some way.