`
Robinson
  • 浏览: 88008 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

mysql日志清理

    博客分类:
  • DB
阅读更多

mysql>SHOW MASTER LOGS;
此命令显示目前二进制日志的数目。
然后
mysql> PURGE MASTER LOGS TO ‘binary-log.xxx’;

 mysql > flush logs;

 mysql > reset master;


除了命令中给出的日志之后的外,其他的二进制日志全部删除。

具体如下:
PURGE MASTER LOGS

PURGE { MASTER|BINARY } LOGS TO ‘log_name’
PURGE { MASTER|BINARY } LOGS BEFORE ‘date’

Deletes all the binary logs listed in the log index that are strictly prior to the specified log or date. The logs also are removed from this list recorded in the log index file, so that the given log now becomes the first.

Example:

PURGE MASTER LOGS TO ‘mysql-bin.010′;
PURGE MASTER LOGS BEFORE ’2003-04-02 22:46:26′;

The BEFORE variant is available in MySQL 4.1; its date argument can be in ‘YYYY-MM-DD hh:mm:ss’ format. MASTER and BINARY are synonyms, though BINARY can be used only as of MySQL 4.1.1.

If you have an active slave that is currently reading one of the logs you are trying to delete, this command does nothing and fails with an error. However, if you have a dormant slave, and happen to purge one of the logs it wants to read, the slave will be unable to replicate once it comes up. The command is safe to run while slaves are replicating. You do not need to stop them.

You must first check all the slaves with SHOW SLAVE STATUS to see which log they are reading, then do a listing of the logs on the master with SHOW MASTER LOGS, find the earliest log among all the slaves (if all the slaves are up to date, this will be the last log on the list), backup all the logs you are about to delete (optional) and purge up to the target log.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics