Home > Database > Mysql Tutorial > MySQL--binlog日志恢复数据_MySQL

MySQL--binlog日志恢复数据_MySQL

WBOY
Release: 2016-06-01 13:39:18
Original
781 people have browsed it

bitsCN.com
MySQL--binlog日志恢复数据 恢复数据的重要命令如下mysql> flush logs;  默认的日志是mysql-bin.000001,现在刷新了重新开启一个就多了一个mysql-bin.000002                                ./mysqlbinlog --no-defaults binlog日志名,来查看日志[root@localhost bin]# ./mysqlbinlog --no-defaults ../var/mysql-bin.000001 | more     //查看bin-log日志的内容[root@localhost bin]# ./mysqlbinlog --no-defaults ../var/mysql-bin.000001 | ./mysql -uroot -p //恢复mysql-bin.000001日志的内容如果需要从某个点恢复到某个点,用以下操作定位: --start-position 开始点--stop-position 结束点--start-date 开始时间--stop-date  结束时间   现在恢复mysql-bin.000002恢复,从134点开始到386结束   [root@localhost bin]# ./mysqlbinlog --no-defaults --start-position 134 --stop-position=386 ../var/mysql-bin.000002 | ./mysql -uroot -p /**        mysqlbinlog日志恢复数据实验         ****///查看一下var下面的内容,现在是没有mysql-log.000001类似的binlog日志的[root@localhost var]# lsbrocms       ibdata1      ib_logfile1    localhost.pid  mysql-bin.indexbrotherblog  ib_logfile0  localhost.err  mysql          test[root@localhost var]# ../bin/mysql -uroot -p //登录数据库mysql> use test; //使用test数据库mysql> flush logs; //刷新binlog日志,新开一个,现在会在var目录下面生成一个mysql-bin.000001的文件,以下的操作都会记录其中 //创建一个表mysql> create table user(    -> id int auto_increment primary key,    -> username char(30),    -> password char(32))    -> engine=myisam default charset=utf8;//插入几条测试数据mysql> insert into user(username,password) values(1,2);mysql> insert into user(username,password) values(1,2);mysql> insert into user(username,password) values(1,2);//新开一个binlog日志,现在会生成一个名为mysql-bin.000002的文件,下面的操作会记录在mysql-bin.000002的文件中 mysql> flush logs;//查询一下内容mysql> select * from user;+----+----------+----------+| id | username | password |+----+----------+----------+|  1 | 1        | 2        ||  2 | 1        | 2        ||  3 | 1        | 2        |+----+----------+----------+mysql> delete from user; //现在将数据删除mysql> drop table user; //将表删除mysql> select * from user; //查看表里面的内容 mysql> /qBye[root@localhost var]# lsbrocms       ibdata1      ib_logfile1    localhost.pid  mysql-bin.000001  mysql-bin.indexbrotherblog  ib_logfile0  localhost.err  mysql          mysql-bin.000002  test[root@localhost var]# ../bin/mysqlbinlog --no-defaults mysql-bin.000001 | more //查看mysql-bin.000001里面的内容[root@localhost var]# ../bin/mysqlbinlog --no-defaults mysql-bin.000002 | more //查看mysql-bin.000002里面的内容[root@localhost var]# ../bin/mysqlbinlog --no-defaults mysql-bin.000001 | ../bin/mysql -uroot -p //用mysql-bin.000001来恢复数据   Enter password:[root@localhost var]# ../bin/mysql -uroot -p //进数据库查看mysql> use test;mysql> show tables;+----------------+| Tables_in_test |+----------------+| user           |+----------------+1 row in set (0.00 sec) mysql> select * from user; //查看数据,数据回来了+----+----------+----------+| id | username | password |+----+----------+----------+|  1 | 1        | 2        ||  2 | 1        | 2        ||  3 | 1        | 2        |+----+----------+----------+3 rows in set (0.00 sec) mysql> /qBye   如果需要从某个点恢复到某个点,用以下操作定位: --start-position 开始点--stop-position 结束点--start-date 开始时间--stop-date  结束时间 现在恢复mysql-bin.000002恢复,从134点开始到386结束   [root@localhost bin]# ./mysqlbinlog --no-defaults --start-position 134 --stop-position=386 ../var/mysql-bin.000002 | ./mysql -uroot -p  bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template