{"id":438,"date":"2015-09-15T07:10:45","date_gmt":"2015-09-15T07:10:45","guid":{"rendered":"http:\/\/kb.veeble.org\/?p=438"},"modified":"2025-04-15T13:21:57","modified_gmt":"2025-04-15T07:51:57","slug":"how-to-clear-or-purge-mysql-bin-log-files","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/how-to-clear-or-purge-mysql-bin-log-files\/","title":{"rendered":"How to clear or purge MySQL Bin log Files"},"content":{"rendered":"\n<p><strong>Binary log<\/strong><\/p>\n\n\n\n<p>MySQL&#8217;s Official website defines the binary log as follows:<\/p>\n\n\n\n<p>The binary log contains \u201cevents\u201d that describe database changes such as table creation operations or changes to table data. It also contains events for statements that potentially could have made changes (for example, a DELETE that matched no rows). The binary log also contains information about how long each statement took that update data. The binary log has two important purposes:<\/p>\n\n\n\n<p>a) Data replication<\/p>\n\n\n\n<p>b)&nbsp;Also certain data recovery options require this binary log<\/p>\n\n\n\n<p>Considering the replication purpose, it is necessary to clear the old logs for the proper functioning of replication. Also clearing the old logs will free up a large about of disk space.<\/p>\n\n\n\n<p>Here is some example commands to clear\/purge MySQL binary logs.<\/p>\n\n\n\n<p>Access the MySQL prompt.<\/p>\n\n\n\n<p>The following command will delete all logs prior to the log file mysql-bin.0003<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; PURGE BINARY LOGS TO 'mysql-bin.0003';<\/pre>\n\n\n\n<p>The following command will delete all logs before 2015-09-15<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; PURGE BINARY LOGS BEFORE '2015-09-15 10:00:00';<\/pre>\n\n\n\n<p>The following command will delete all logs older than 7 days.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 7 DAY);<\/pre>\n\n\n\n<p>The following command will delete all logs till now.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; PURGE BINARY LOGS BEFORE now();<\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">expire_logs_days = 10\nmax_binlog_size = 100M<\/pre>\n\n\n\n<p>Restart mysql server<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/etc\/init.d\/mysql restart<\/pre>\n\n\n\n<p>Done!<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-d7f0d786 wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Powering Your Business with Windows VPS<\/h3><p class=\"uagb-cta__desc\">Choose a robust and reliable platform for your critical applications. Experience the difference a high-performance VPS can make.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/vps-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">Choose Your Plan<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Binary log MySQL&#8217;s Official website defines the binary log as follows: The binary log contains \u201cevents\u201d that describe database changes such as table creation [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":8601,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[11],"tags":[],"class_list":["post-438","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/09\/How-to-clear-or-purge-MySQL-Bin-log-Files.jpg",1366,768,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/09\/How-to-clear-or-purge-MySQL-Bin-log-Files-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/09\/How-to-clear-or-purge-MySQL-Bin-log-Files-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/09\/How-to-clear-or-purge-MySQL-Bin-log-Files-768x432.jpg",768,432,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/09\/How-to-clear-or-purge-MySQL-Bin-log-Files-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/09\/How-to-clear-or-purge-MySQL-Bin-log-Files.jpg",1366,768,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2015\/09\/How-to-clear-or-purge-MySQL-Bin-log-Files.jpg",1366,768,false]},"uagb_author_info":{"display_name":"Vipin Raj","author_link":"https:\/\/www.veeble.com\/kb\/author\/vipin\/"},"uagb_comment_info":0,"uagb_excerpt":"Binary log MySQL&#8217;s Official website defines the binary log as follows: The binary log contains \u201cevents\u201d that describe database changes such as table creation [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=438"}],"version-history":[{"count":9,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/438\/revisions"}],"predecessor-version":[{"id":7189,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/438\/revisions\/7189"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/8601"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}