14 rows in set (0.00 sec)
可以看出,整个数据插入在692到870之间。下面做恢复:
[root@channelme~]# mysqlbinlog -uroot -p --start-position=692 mysqlbin.000021
Enter password:
/*!40019 SET@@session.max_insert_delayed_threads=0*/;
/*!50003 SET@OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
mysqlbinlog: File 'mysqlbin.000021' notfound (Errcode: 2)
DELIMITER ;
# End of log file
[root@channelme ~]# mysqlbinlogmysql-bin.000021 --start-position=692 --stop-position=870 | mysql -uroot -p
Enter password: mysqlbinlog: File'mysql-bin.000021' not found (Errcode: 2)
注:这里只想着是不是我binlog 的名称是否输错了,根本忘了我在/root下,而日志文件在mysql数据目录下!!!!!
进入data目录:
[root@channelme data]# ls
channel mysql-bin.000001 mysql-bin.000016
……
mysql-bin.000006 mysql-bin.000021 mysql-bin.index
[root@channelmedata]# mysqlbinlog mysql-bin.000021--start-position=692 --stop-position=870 | mysql -uroot -p
Enter password:
[root@channelme data]#
恢复好了。终于没报错,检查一下:
mysql> select *from chanel_following;
+------------+------------+
| id | uid |
+------------+------------+
| 3 | 69686869 |
| 102 | 100000 |
| 2132723743 | 2147483647 |
+------------+------------+
3 rows in set (0.00 sec)
ok,实验完成。
另外注意,如果是盘坏掉,日志文件也会丢失。所以,要想恢复,我们需要MySQL服务器将MySQL二进制日志保存到安全的位置(RAID disks, SAN, ...),应为与数据文件的保存位置不同的地方,保证这些日志不在毁坏的硬盘上。(也就是,我们可以用--log-bin选项启动服务器,指定一个其它物理设备上的与数据目录不同的位置。这样,即使包含该目录的设备丢失,日志也不会丢失)。
自己写的,防止丢失,便于查阅。。。欢迎指正。上传后,有空格被丢掉,模拟的童鞋注意别错了。