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.
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.
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.
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With