MySQL Purge Binary Logs: Difference between revisions

From UNIX Systems Administration
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
# Change to the directory containing the binary log files.
# Change to the directory containing the binary log files.
## Note the last time on the first to newest mysql-bin.######, use that time for the purge binary logs before command.
# Login to the all slave servers.
# Flush the logs.
## <tt>'''# mysql -p -uroot'''</tt>
### Check which log file it is reading.
#### <tt>'''mysql> SHOW SLAVE STATUS;'''</tt>
### Determine the earliest log file among all the slaves. This is the target file. If all the slaves are up to date, this is the last log file on the list.
# On the master server, flush the logs.
## <tt>'''# mysqladmin flush-logs -p -uroot'''</tt>
## <tt>'''# mysqladmin flush-logs -p -uroot'''</tt>
# Login to MySQL.
# Login to the master server.
## <tt>'''mysql -p -uroot'''</tt>
## <tt>'''# mysql -p -uroot'''</tt>
### Obtain a listing of the binary log files.
#### <tt>'''mysql> SHOW BINARY LOGS;'''</tt>
# Make a backup of all the log files you are about to delete. (This step is optional, but always advisable.)
# Purge the binary logs.
# Purge the binary logs.
## <tt>'''mysql> purge binary logs before 'yyyy-mm-dd hh:mm:ss''''</tt> (note: the seconds is optional)
## <tt>'''mysql> PURGE BINARY LOGS BEFORE 'yyyy-mm-dd hh:mm:ss';'''</tt> (note: the seconds is optional)


== Further Reading ==
== Further Reading ==

Revision as of 12:02, 26 July 2012

  1. Change to the directory containing the binary log files.
  2. Login to the all slave servers.
    1. # mysql -p -uroot
      1. Check which log file it is reading.
        1. mysql> SHOW SLAVE STATUS;
      2. Determine the earliest log file among all the slaves. This is the target file. If all the slaves are up to date, this is the last log file on the list.
  3. On the master server, flush the logs.
    1. # mysqladmin flush-logs -p -uroot
  4. Login to the master server.
    1. # mysql -p -uroot
      1. Obtain a listing of the binary log files.
        1. mysql> SHOW BINARY LOGS;
  5. Make a backup of all the log files you are about to delete. (This step is optional, but always advisable.)
  6. Purge the binary logs.
    1. mysql> PURGE BINARY LOGS BEFORE 'yyyy-mm-dd hh:mm:ss'; (note: the seconds is optional)

Further Reading

  1. MySQL Reference Guide - PURGE BINARY LOGS Syntax