Skip to content

Instantly share code, notes, and snippets.

@iAugur
Last active December 12, 2015 01:28
Show Gist options
  • Save iAugur/4691272 to your computer and use it in GitHub Desktop.
Save iAugur/4691272 to your computer and use it in GitHub Desktop.
Purge MySQL binary logs
rem Windows batch file for WAMP
@ECHO OFF
For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (Set Datestr=%%c-%%b-%%a)
FOR /F "TOKENS=*" %%A IN ('TIME/T') DO SET TIME=%%A
echo Purging Logs on %Datestr% >> d:/wamp/logs/mysql-log-purge.log
@echo off
echo. | time /t
echo Purge Binary Logs .
D:\wamp\bin\mysql\mysql5.1.36\bin\mysql.exe -u root -p -e "PURGE BINARY LOGS BEFORE '%Datestr% 00:00:01';"
echo D:\wamp\bin\mysql\mysql5.1.36\bin\mysql.exe -u root -p -e "PURGE BINARY LOGS BEFORE '%Datestr% 00:00:01';"
echo Completed, Purged Binary Logs
echo. | time /t
pause
cls
if %errorlevel% == 0 goto okay
:error
echo Error Purging Binary Logs %Datestr% at %Time% >> d:/wamp/logs/mysql-log-purge.log
eventcreate /t error /id 100 /so MYSQLPurge /l application /d "MYSqlPurge - Error"
goto end
:okay
rem eventcreate /t information /id 101 /so MYSQLPurge /l application /d "MYSQLPurge - Success"
:end
#!/bin/bash
# Bash script to run every now and then
# source:http://knowledge-republic.com/CRM/2011/05/removing-of-binary-log-bash-script/
user=root
password=password
mysql -u$user -p$password -bse “show binary logs;” > binary.log
LastLine=`tail -n1 binary.log|awk ‘{print $1}’`
mysql -u$user -p$password -bse “purge binary logs to ‘”$LastLine”‘;”
rm binary.log
# At the command line
# You can clear them up to a date or up to a specific log file:
#
$ mysql -u root -p 'rootpassword' -e "PURGE BINARY LOGS TO 'mysql-bin.00054';"
- or -
$ mysql -u root -p 'rootpassword' -e "PURGE BINARY LOGS BEFORE '2013-01-01 10:00:00';"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment