Rana
Rana

Reputation: 6154

Clear MySQL General Log Table, Is It Safe?

I server I am working on, general mysql log table is taking near 200GB space, which is huge. So, I am planning to clear it up with:

TRUNCATE table mysql.general_log

Is it ok? Will it cause any issue? I am concerned as the server is live and big application. Thanks.

Upvotes: 23

Views: 36962

Answers (2)

mysqlrockstar
mysqlrockstar

Reputation: 2612

It will definitely cause a problem unless it is disabled and then you truncate. If you truncate while it is enabled. Truncate will lock the table if table is huge, since mysql.general_log engine is either CSV or MyISAM ,meanwhile newly made entries will try to be written in general log table causing a lock. So for safety do like this

mysql> SET GLOBAL general_log=OFF;
mysql> TRUNCATE table mysql.general_log;
mysql> SET GLOBAL general_log=ON;

Upvotes: 37

0xfded
0xfded

Reputation: 79

It won't cause problems, but you will lose all the old log entries, so Ravindra's advice above is good.

You can do a backup with:

mysqldump -p --lock_tables=false mysql general_log > genlog.sql

Do you need to have the general log on all the time? I usually only turn it on when I'm troubleshooting performance issues. MySQL logs EVERYTHING there (client connects, disconnects, and EVERY statement). In most systems, the logs get very big very quickly. There is also some performance overhead for this.

Upvotes: 6

Related Questions