使用 MYSQLBINLOG 来恢复数据
2009-04-05 12:47:05
1、配置文件里要写的东西:
[mysqld]
log-bin=mysql-bin(名字可以改成自己的,如果不改名字的话,默认是以主机名字命名)
重新启动MSYQL服务。
二进制文件里面的东西显示的就是执行所有语句的详细记录,当然一些语句不被记录在内,要了解详细的,见手册页。
2、查看自己的BINLOG的名字是什么。
show binlog events;
query result(1 records)
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
| yueliangdao_binglog.000001 | 4 | Format_desc | 1 | 106 | Server ver: 5.1.22-rc-community-log, Binlog ver: 4 |
3、我做了几次操作后,她就记录了下来。
又一次 show binlog events 的结果。
query result(4 records)
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
| yueliangdao_binglog.000001 | 4 | Format_desc | 1 | 106 | Server ver: 5.1.22-rc-community-log, Binlog ver: 4 |
| yueliangdao_binglog.000001 | 106 | Intvar | 1 | 134 | INSERT_ID=1 |
| yueliangdao_binglog.000001 | 134 | Query | 1 | 254 | use `test`; create table a1(id int not null auto_increment primary key, str varchar(1000)) engine=myisam |
| yueliangdao_binglog.000001 | 254 | Query | 1 | 330 | use `test`; insert into a1(str) values ('I love you'),('You love me') |
| yueliangdao_binglog.000001 | 330 | Query | 1 | 485 | use `test`; drop table a1 |
详细过程如下:
D:\LAMP\MYSQL5\data>mysqlbinlog --start-position=4 --stop-position=106 yueliangd
ao_binglog.000001 > c:\\test1.txt
test1.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 file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
第二行的记录:
D:\LAMP\MYSQL5\data>mysqlbinlog --start-position=106 --stop-position=134 yuelian
gdao_binglog.000001 > c:\\test1.txt
test1.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 Intvar
SET INSERT_ID=1/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
第三行记录:
D:\LAMP\MYSQL5\data>mysqlbinlog --start-position=134 --stop-position=254 yuelian
gdao_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=0
use 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 file
ROLLBACK /* 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 yuelian
gdao_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=0
use 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 file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
5、查看这些东西是为了恢复数据,而不是为了好玩。所以我们最中还是为了要导入结果到MYSQL中。
D:\LAMP\MYSQL5\data>mysqlbinlog --start-position=134 --stop-position=330 yuelian
gdao_binglog.000001 | mysql -uroot -p
或者
D:\LAMP\MYSQL5\data>mysqlbinlog --start-position=134 --stop-position=330 yuelian
gdao_binglog.000001 >test1.txt
进入MYSQL导入
mysql> source c:\\test1.txt
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Database changed
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Charset changed
Query 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)
./mysqlbinlog /usr/local/mysql/data/mysql-bin.000001 > /opt/001.sql
本文出自 “聆听未来” 博客,请务必保留此出处http://kerry.blog.51cto.com/172631/146259
使用 MYSQLBINLOG 来恢复数据的更多相关文章
- [转] 使用 MYSQLBINLOG 来恢复数据
使用 MYSQLBINLOG 来恢复数据 2009-04-05 12:47:05 标签:mysql mysqlbinlog 恢复 数据库 数据 原创作品,允许转载,转载时请务必以超链接形式标明文章 ...
- 练手mysqlbinlog日志恢复数据(centos6.5 64,mysql5.1)
练手mysql bin log日志相关 系统是centos 6.5 64 阿里云的服务器 mysql版本5.1 1 如何开启bin-log日志? vi /etc/my.cnf [mysqld] log ...
- mysqlbinlog恢复数据-update20140820
mysqlbinlog恢复数据 BINLOG就是一个记录SQL语句的过程,和普通的LOG一样.只是它是二进制存储,普通的是十进制存储. ================================ ...
- 使用mysqlbinlog恢复数据
前提:mysql数据库开启了binlog日志,并且有对应的日志文件 起因:今天由于同事对数据库的误操作不小心删除了一条数据 方法一:通过binlog日志文件恢复数据 通过mysqlbinlog恢复My ...
- mysqlbinlog恢复数据注意事项【转】
mysqlbinlog 恢复数据注意事项 前言: 上次有个有个朋友恢复 MySQL 数据,一直恢复不成功,也没有报错信息,使用的环境是 MySQL 5.7 使用了 GTID 以及 binlog 格式为 ...
- 从binlog恢复数据及Mysqlbinlog文件删除
做了mysql主从也有一段时间了,这两天检查磁盘空间情况,发现放数据库的分区磁盘激增了40多G,一路查看下来,发现配置好主从复制以来到现在的binlog就有40多G,原来根源出在这里,查看了一下my. ...
- mysqlbinlog 恢复数据到任意时间点
创建表,插入数据. ``` mysql> create database binlog; mysql> create table bt(id int); mysql> insert ...
- mysql数据安全之利用二进制日志mysqlbinlog恢复数据
mysql数据安全之利用二进制日志mysqlbinlog恢复数据 简介:如何利用二进制日志来恢复数据 查看二进制日志文件的内容报错: [root@xdclass-public log_bin]# my ...
- 【转】【MySQL】mysql 通过bin-log恢复数据方法详解
mysql中bin-log在mysql默认状态下是没有打开的,我们要先打开mysql 开启bin-log功能,然后再通过备份的bin-log进行数据库恢复了. 具体的操作是通过mysqlbinlog这 ...
随机推荐
- Leetcode 12,452,455-贪心算法
Leetcode第12题,整数转罗马数字,难度中等 整个题目比较好理解,难度也不大,就算不过脑子,用一串if也基本上可以解决问题,比如 /** 执行用时:6ms,在所有 Java 提交中击败了52.6 ...
- 【转载】五分钟让你彻底了解TDD、ATDD、BDD&RBE
在目前比较流行的敏捷开发模式(如极限编程.Scrum方法等)中,推崇“测试驱动开发(Test Driven Development,TDD)”——测试在先.编码在后的开发实践.TDD有别于以往的“先编 ...
- nyoj 57
6174问题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 假设你有一个各位数字互不相同的四位数,把所有的数字从大到小排序后得到a,从小到大后得到b,然后用a-b替 ...
- day04-MyBatis的注解开发
单表的CRUD注解开发: User实体类: package com.zyb.pojo; import java.io.Serializable; import java.util.Date; publ ...
- php基础 php 全局变量
$_GET ----->get传送方式 $_POST ----->post传送方式 $_REQUEST ----->可以接收到get和post两种方式的值 $GLOBALS ---- ...
- php 算法知识 猴子选大王
一群猴子排成一圈,按1,2,...,n依次编号. 然后从第1只开始数,数到第m只,把它踢出圈, 从它后面再开始数,再数到第m只,在把它踢出去..., 如此不停的进行下去,直到最后只剩下一只猴子为止,那 ...
- Mysql基本用法-存储引擎-03
看到存储引擎这个地方感到很多细节比较陌生,所以总结小记一些 为了适应各种不同的运行环境,MYSQL提供了多种不同的存储引擎(Storage Engine ),在应用程序开发这个层面上,开发者可以根据不 ...
- 并发编程之第三篇(synchronized)
并发编程之第三篇(synchronized) 3. 自旋优化 4. 偏向锁 撤销-其它线程使用对象 撤销-调用wait/notify 批量重偏向 批量撤销 5. 锁消除 4.7 wait/notify ...
- Python第五十一天 python2升级为python3
Python第五十一天 python2升级为python3 公司使用的生产环境系统是centos7,所以这里以centos7系统为基础,讲解将python2升级为python3的方法 centos7 ...
- 03.使用私有构造方法或枚类实现 Singleton 属性
前言 <Effective Java>中文第三版,是一本关于Java基础的书,这本书不止一次有人推荐我看.其中包括我很喜欢的博客园博主五月的仓颉,他曾在自己的博文<给Java程序猿们 ...