MySQL 二进制日志(Binary Log)(5)

root@localhost[tempdb]> show binlog events in 'binlog.000004' from 374;
+---------------+-----+------------+-----------+-------------+------------------------------------------------+
| Log_name      | Pos | Event_type | Server_id | End_log_pos | Info                                          |
+---------------+-----+------------+-----------+-------------+------------------------------------------------+
| binlog.000004 | 374 | Query      |        1 |        471 | use `tempdb`; insert into tb1 values(1,'jack') |
| binlog.000004 | 471 | Xid        |        1 |        498 | COMMIT /* xid=25 */                            |
+---------------+-----+------------+-----------+-------------+------------------------------------------------+

root@localhost[tempdb]> show binlog events in 'binlog.000004' from 374 limit 1;
+---------------+-----+------------+-----------+-------------+------------------------------------------------+
| Log_name      | Pos | Event_type | Server_id | End_log_pos | Info                                          |
+---------------+-----+------------+-----------+-------------+------------------------------------------------+
| binlog.000004 | 374 | Query      |        1 |        471 | use `tempdb`; insert into tb1 values(1,'jack') |
+---------------+-----+------------+-----------+-------------+------------------------------------------------+


d、删除历史日志
--使用purge手动删除指定日志
--使用expire-log-days删除失效日志,设置变量expire_logs_days,删除超出这个变量保留期之前的所有日志被删除
--自动日志删除通常发生在服务器启动以及日志flush
--reset master方式
root@localhost[(none)]> help purge;
Name: 'PURGE BINARY LOGS'
Description:
Syntax:
PURGE { BINARY | MASTER } LOGS
    { TO 'log_name' | BEFORE datetime_expr }

Examples:
PURGE BINARY LOGS TO 'mysql-bin.010';
PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';

root@localhost[tempdb]> purge binary logs to 'binlog.000003';
Query OK, 0 rows affected (0.12 sec)

root@localhost[tempdb]> show binary logs;
+---------------+-----------+
| Log_name      | File_size |
+---------------+-----------+
| binlog.000003 |      147 |
| binlog.000004 |      498 |
+---------------+-----------+

root@localhost[tempdb]> system ls -hltr /var/lib/mysql/binarylog/*
-rw-rw---- 1 mysql mysql 147 Oct  3 13:46 /var/lib/mysql/binarylog/binlog.000003
-rw-rw---- 1 mysql mysql 498 Oct  3 14:09 /var/lib/mysql/binarylog/binlog.000004
-rw-rw---- 1 mysql mysql  78 Oct  3 14:23 /var/lib/mysql/binarylog/binlog.index

--使用before子句purge日志,binlog.000003被删除
root@localhost[tempdb]> purge binary logs before '2014-10-03 14:09:56';
Query OK, 0 rows affected (0.02 sec)

root@localhost[tempdb]> show binary logs;
+---------------+-----------+
| Log_name      | File_size |
+---------------+-----------+
| binlog.000004 |      498 |
+---------------+-----------+

--Author: Leshami
--Blog  :
--重置所有日志
--reset master将删除在索引文件中列出所有的日志文件并重置索引文件,最后生成一个新的binlog文件。
--该操作之前先备份binlog至其它位置以备以后需要。
root@localhost[tempdb]> help reset master;
Name: 'RESET MASTER'
Description:
Syntax:
RESET MASTER

Deletes all binary log files listed in the index file, resets the
binary log index file to be empty, and creates a new binary log file.
This statement is intended to be used only when the master is started
for the first time.

root@localhost[tempdb]> reset master;
Query OK, 0 rows affected (0.13 sec)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/433c9e21fb4c82208680db543bc0137b.html