4、用mysqlbinlog 工具来显示记录的二进制结果,然后导入到文本文件,为了以后的恢复。详细过程如下:D:\LAMP\MYSQL5\data>mysqlbinlog --start-position=4 --stop-position=106 yueliangdao_binglog.000001 > c:\\test1.txttest1.txt的文件内容:/*!40019 SET @@session.max_insert_delayed_threads=0*/;/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;DELIMITER /*!*/;# at 4#7122 16:9:18 server id 1 end_log_pos 106 Start: binlog v 4, server v 5.1.22-rc-community-log created 7122 16:9:18 at startup# Warning: this binlog was not closed properly. Most probably mysqld crashed writing it.ROLLBACK/*!*/;DELIMITER ;# End of log fileROLLBACK /* added by mysqlbinlog */;/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;第二行的记录:D:\LAMP\MYSQL5\data>mysqlbinlog --start-position=106 --stop-position=134 yueliangdao_binglog.000001 > c:\\test1.txttest1.txt内容如下:/*!40019 SET @@session.max_insert_delayed_threads=0*/;/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;DELIMITER /*!*/;# at 106#7122 16:22:36 server id 1 end_log_pos 134 IntvarSET INSERT_ID=1/*!*/;DELIMITER ;# End of log fileROLLBACK /* added by mysqlbinlog */;/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;第三行记录:D:\LAMP\MYSQL5\data>mysqlbinlog --start-position=134 --stop-position=254 yueliangdao_binglog.000001 > c:\\test1.txt内容:/*!40019 SET @@session.max_insert_delayed_threads=0*/;/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;DELIMITER /*!*/;# at 134#7122 16:55:31 server id 1 end_log_pos 254 Query thread_id=1 exec_time=0 error_code=0use test/*!*/;SET TIMESTAMP=1196585731/*!*/;SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1/*!*/;SET @@session.sql_mode=1344274432/*!*/;/*!\C utf8 *//*!*/;SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;create table a1(id int not null auto_increment primary key,str varchar(1000)) engine=myisam/*!*/;DELIMITER ;# End of log fileROLLBACK /* added by mysqlbinlog */;/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;/*!40019 SET @@session.max_insert_delayed_threads=0*/;第四行的记录:D:\LAMP\MYSQL5\data>mysqlbinlog --start-position=254 --stop-position=330 yueliangdao_binglog.000001 > c:\\test1.txt/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;DELIMITER /*!*/;# at 254#7122 16:22:36 server id 1 end_log_pos 330 Query thread_id=1 exec_time=0 error_code=0use test/*!*/;SET TIMESTAMP=1196583756/*!*/;SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1/*!*/;SET @@session.sql_mode=1344274432/*!*/;/*!\C utf8 *//*!*/;SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;use `test`; insert into a1(str) values ('I love you'),('You love me')/*!*/;DELIMITER ;# End of log fileROLLBACK /* added by mysqlbinlog */;/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;5、查看这些东西是为了恢复数据,而不是为了好玩。所以我们最中还是为了要导入结果到MYSQL中。D:\LAMP\MYSQL5\data>mysqlbinlog --start-position=134 --stop-position=330 yueliangdao_binglog.000001 | mysql -uroot -p或者D:\LAMP\MYSQL5\data>mysqlbinlog --start-position=134 --stop-position=330 yueliangdao_binglog.000001 >test1.txt进入MYSQL导入mysql> source c:\\test1.txtQuery OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Database changedQuery OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Charset changedQuery OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.03 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)6、查看数据:mysql> show tables;+----------------+| Tables_in_test |+----------------+| a1 |+----------------+1 row in set (0.01 sec)mysql> select * from a1;+----+-------------+| id | str |+----+-------------+| 1 | I love you || 2 | You love me |+----+-------------+2 rows in set (0.00 sec)
mysql根据日志恢复数据_根据mysql数据库日志恢复删除数据
最新推荐文章于 2024-03-25 23:12:37 发布