740 views
asked in MySQL by

How to clear or purge MySQL Bin log Files

1 Answer

answered by
Access the MySQL prompt.

The following command will delete all logs prior to the log file mysql-bin.0004

mysql> PURGE BINARY LOGS TO 'mysql-bin.0004';

The following command will delete all logs before 2024-02-15

mysql> PURGE BINARY LOGS BEFORE '2024-02-15 10:00:00';

The following command will delete all logs older than 7 days.

mysql> PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 7 DAY);

The following command will delete all logs till now.

mysql> PURGE BINARY LOGS BEFORE now();

You will not need to do purge logs manually, logs older than 10 days will be purged automatically by the MySQL server if you add the following lines in the MySQL configuration file.

expire_logs_days = 10

max_binlog_size = 100M

Restart MySQL server

/etc/init.d/mysql restart

Most popular tags

laravel postgresql laravel-10 replication ha postgresql mongodb laravel-11 mongodb database mongodb tutorial ubuntu 24.04 lts streaming-replication mysql database laravel postgresql backup laravel login register logout database mysql php laravel 11 - login with otp valid for 10 minutes. user and admin registration user and admin login multiauth technlogy asp.net asp.net c# mysql master slave replication centos linux laravel sql server schedule backup autobackup postgresql django python haproxy load balancer install self sign ssl laravel 11 gaurds zabbix 7 how to install graylog on ubuntu 24.04 lts | step-by-step asp.net core mvc .net mvc network upload c# ssl integration sql server on ubuntu 22.04 lts mssql server ms sql server sql server user access in postgres mysql password change cent os linux configure replica laravel 11 socialite login with google account google login kubernetes (k8s) install nginx load balancer install install and configure .net 8.0 in ubuntu 24.04 lts php in iis php with iis php tutorial chirags php tutorials chirags php tutorial chirags tutorial laravel 11 guards mongodb sharding metabase business analytics metabase postgresql 16 to postgresql 17 postgresql migration letsencrypt mongodb crud rocky linux laravel custom captcha laravel 11 captcha laravel captcha mongo dll php.ini debian 12 nginx apache nextcloud gitea in ubuntu git gitea npm error node js mysql ndb cluster mysql cluster ssl oracle login register logout in python debian windows shell batch file bat file time stamp date time shopping cart in laravel centos rhel swap memeory rhel 5.5
...