AntmadDG
AntmadDG

Reputation: 66

How to limit MySQL general_log file size?

I need to save general_log into a file and to avoid the file is too large.

MariaDB 10.3

#This is the settings I write in the my.cnf.
[mysqld]
general_log_file = /var/log/mysql/mysql.log
general_log = 1

I know there is way to set log_bin size or expire time, is there a way to set the general_log? Or must I remove the file by crontab or manually.

Upvotes: 3

Views: 5648

Answers (2)

JCH77
JCH77

Reputation: 1363

I just have the same problem. It seems MySQL can't limit the size of the general.log file.

I finally use this command in a crontab to keep general.log last 20,000 lines :

$ tail -20000 /path/to/mysql/general.log | sponge /path/to/mysql/general.log

It's not perfect beaucause a request can be logged on mutiple lines.

If sponge is not available :

$ apt install moreutils

Upvotes: 1

sandesh dahake
sandesh dahake

Reputation: 1026

I am not aware, official documents also does not specify any such configuration. We have configured it as part of startup script and cron tab for daily archival

Upvotes: 0

Related Questions