Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear MySQL General Log Table, Is It Safe?

Tags:

logging

mysql

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.

like image 593
Rana Avatar asked Feb 03 '13 06:02

Rana


People also ask

How do I purge general logs in MySQL?

To force MySQL to start using new log files, flush the logs. Log flushing occurs when you execute a FLUSH LOGS statement or a mysqladmin flush-logs, mysqladmin refresh, mysqldump --flush-logs, or mysqldump --master-data command.

What is MySQL general log?

The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients.


2 Answers

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;
like image 75
koustuv Avatar answered Sep 17 '22 17:09

koustuv


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.

like image 21
0xfded Avatar answered Sep 17 '22 17:09

0xfded