使用mysqlbinlog恢复数据
mysqlbinlog工具的使用,大家可以看MySQL的帮助手册。里面有详细的用,
在这个例子中,重点是--start-position参数和--stop-position参数的使用。
?--start-position=N
从二进制日志中第1个位置等于N参量时的事件开始读。
?--stop-position=N
从二进制日志中第1个位置等于和大于N参量时的事件起停止读。
OK,现在开始,要启动二进制日志记录,
要先在my.cnf / my.ini文件的mysqld里添加
log-bin=日志名
在这里,偶是的设置是log-bin=liangck
然后再启动mysql服务,因为偶是用windows系统,
所以执行net start mysql命令即可。
然后在一测试数据库里,创建一个表,并添加记录。
mysql> create table test(id int auto_increment not null primary key, val int,data varchar(20));mysql> insert into test(val,data) values(10,'liang');Query OK, 1 row affected (0.03 sec)mysql> insert into test(val,data) values(20,'jia');Query OK, 1 row affected (0.08 sec)mysql> insert into test(val,data) values(30,'hui');Query OK, 1 row affected (0.03 sec)mysql> flush logs; --产生第二个日志文件Query OK, 0 rows affected (0.09 sec)mysql> insert into test(val,data) values(40,'aaa');Query OK, 1 row affected (0.05 sec)mysql> insert into test(val,data) values(50,'bbb');Query OK, 1 row affected (0.03 sec)mysql> insert into test(val,data) values(60,'ccc');Query OK, 1 row affected (0.03 sec)mysql> delete from test where id between 4 and 5; --删除记录Query OK, 2 rows affected (0.05 sec)mysql> insert into test(val,data) values(70,'ddd');Query OK, 1 row affected (0.03 sec)mysql> flush logs; --产生第三个文件文件Query OK, 0 rows affected (0.11 sec)mysql> insert into test(val,data) values(80,'dddd');Query OK, 1 row affected (0.05 sec)mysql> insert into test(val,data) values(90,'eeee');Query OK, 1 row affected (0.03 sec)mysql> drop table test; --删除表Query OK, 0 row affected (0.05 sec)
mysql> select * from test;+----+------+-------+| id | val | data |+----+------+-------+| 1 | 10 | liang || 2 | 20 | jia || 3 | 30 | hui || 4 | 40 | aaa || 5 | 50 | bbb || 6 | 60 | ccc || 7 | 70 | ddd || 8 | 80 | dddd || 9 | 90 | eeee |+----+------+-------+9 rows in set (0.00 sec)