Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MySQL, how can I delete/flush/clear all the logs that are not necessary?

Tags:

logging

mysql

I have tried several commands (FLUSH LOGS, PURGE MASTER) but none deletes the log files (when previously activated) or the log tables (mysql/slow_log.CSV and mysql/general_log.CSV and their .frm and .CSM counterparts).

SHOW BINARY LOGS returns "You are not using binary logging".

Edit: I found this simple solution to clear the table logs (but not yet the file logs using a mysql command):

TRUNCATE mysql.general_log; TRUNCATE mysql.slow_log; 
like image 241
Erwin Mayer Avatar asked Sep 11 '11 21:09

Erwin Mayer


People also ask

How do I clear MySQL logs?

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.

Can I delete MySQL bin log files?

To resolve this issue, we need to purge the MySQL binary log files. - The PURGE BINARY LOGS statement deletes all the binary log files listed in the log index file prior to the specified log file name or date. BINARY and MASTER are synonyms.

Which command in MySQL can be used to erase the entire database?

To do delete a database you need the command 'DROP DATABASE'. The syntax is similar to creating a database. 'DROP DATABASE <name>;', where <name> is the name of the database you want to delete.

What is the use of flush table in MySQL?

The idea of FLUSH TABLES is to force all tables to be closed. This is mainly to ensure that if someone adds a new table outside of MySQL (for example, by copying files into a database directory with cp ), all threads will start using the new table.


2 Answers

FLUSH LOGS just closes and reopens log files. If the log files are large, it won't reduce them. If you're on Linux, you can use mv to rename log files while they're in use, and then after FLUSH LOGS, you know that MySQL is writing to a new, small file, and you can remove the old big files.

Binary logs are different. To eliminate old binlogs, use PURGE BINARY LOGS. Make sure your slaves (if any) aren't still using the binary logs. That is, run SHOW SLAVE STATUS to see what binlog file they're working on, and don't purge that file or later files.

Also keep in mind that binlogs are useful for point-in-time recovery in case you need to restore from backups and then reapply binlogs to bring the database up to date. If you need to use binlogs in this manner, don't purge the binlogs that have been written since your last backup.

like image 59
Bill Karwin Avatar answered Oct 03 '22 09:10

Bill Karwin


If you are on amazon RDS, executing this twice will do the trick:

PROMPT> CALL mysql.rds_rotate_slow_log; PROMPT> CALL mysql.rds_rotate_general_log; 

Source: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.MySQL.html

like image 38
Joan-Diego Rodriguez Avatar answered Oct 03 '22 09:10

Joan-Diego Rodriguez