MariaDB Store General Query Log in database

  • Last update: Apr 3, 2024
  • Views: 16
  • Author: Admin
MariaDB Store General Query Log in database

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.

 

Article content:

  1. Variable log_output.
  2. 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';

general_log

 

The log_output variable is dynamic, so we can change its value with the SET GLOBAL command.

mariadb> SET GLOBAL log_output = 'TABLE';

general_log

 

And of course, add the variable to the configuration file.

general_log

 

All logs will be written to the mysql.general_log table.

general_log


 

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;

general_log


 

Thank you all, I hope that my article helped you in some way.

SIMILAR ARTICLES