mysqlbinlog日志恢復(fù)數(shù)據(jù)
嗨!有段時間沒有更新了,最近有好多人加我說要進群的,由于當(dāng)時建群沒人進,再加上最近一段時間比較忙,就無奈先解散了哈哈哈,抱歉了各位!
ok,回歸正文
恢復(fù)數(shù)據(jù)的重要命令如下
flush logs;默認的日志是mysql-bin.000001
現(xiàn)在刷新了重新開啟一個就多了一個mysql-bin.000002
./mysqlbinlog --no-defaults binlog日志名,來查看日志
[root bin]# ./mysqlbinlog --no-defaults ../var/mysql-bin.000001 | more //查看bin-log日志的內(nèi)容[root?bin]#?./mysqlbinlog?--no-defaults?../var/mysql-bin.000001?|?./mysql?-uroot?-p?//恢復(fù)mysql-bin.000001日志的內(nèi)容
如果需要從某個點恢復(fù)到某個點,用以下操作
定位:--start-position 開始點
--stop-position 結(jié)束點--start-date 開始時間--stop-date 結(jié)束時間
現(xiàn)在恢復(fù)mysql-bin.000002恢復(fù),從134點開始到386結(jié)束?
[]mysqlbinlog日志恢復(fù)數(shù)據(jù)實驗
//查看一下var下面的內(nèi)容,現(xiàn)在是沒有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 //登錄數(shù)據(jù)庫mysql> use test; //使用test數(shù)據(jù)庫mysql> flush logs; //刷新binlog日志,新開一個,現(xiàn)在會在var目錄下面生成一個mysql-bin.000001的文件,以下的操作都會記錄其中
//創(chuàng)建一個表
mysql> create table user(-> id int auto_increment primary key,-> username char(30),-> password char(32))-> engine=myisam default charset=utf8;
//插入幾條測試數(shù)據(jù)
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日志,現(xiàn)在會生成一個名為mysql-bin.000002的文件,下面的操作會記錄在mysql-bin.000002的文件中
flush logs;查詢一下內(nèi)容
mysql> select * from user;+----+----------+----------+| id | username | password |+----+----------+----------+| 1 | 1 | 2 || 2 | 1 | 2 || 3 | 1 | 2 |+----+----------+----------+
現(xiàn)在將數(shù)據(jù)刪除
mysql> delete from user;將表刪除
drop table user;查看表里面的內(nèi)容
select * from user;\q
[root var]# lsbrocms ibdata1 ib_logfile1 localhost.pid mysql-bin.000001 mysql-bin.indexbrotherblog ib_logfile0 localhost.err mysql mysql-bin.000002 test[root var]# ../bin/mysqlbinlog --no-defaults mysql-bin.000001 | more //查看mysql-bin.000001里面的內(nèi)容[root var]# ../bin/mysqlbinlog --no-defaults mysql-bin.000002 | more //查看mysql-bin.000002里面的內(nèi)容[root var]# ../bin/mysqlbinlog --no-defaults mysql-bin.000001 | ../bin/mysql -uroot -p //用mysql-bin.000001來恢復(fù)數(shù)據(jù)Enter password:[root var]# ../bin/mysql -uroot -p //進數(shù)據(jù)庫查看
數(shù)據(jù)庫操作
mysql> use test;mysql> show tables;+----------------+| Tables_in_test |+----------------+| user |+----------------+1 row in set (0.00 sec)mysql> select * from user; //查看數(shù)據(jù),數(shù)據(jù)回來了+----+----------+----------+| id | username | password |+----+----------+----------+| 1 | 1 | 2 || 2 | 1 | 2 || 3 | 1 | 2 |+----+----------+----------+3 rows in set (0.00 sec)mysql> \q
如果需要從某個點恢復(fù)到某個點,用以下操作
定位:?
--start-position 開始點
--stop-position 結(jié)束點
--start-date 開始時間
--stop-date? 結(jié)束時間
?
現(xiàn)在恢復(fù)mysql-bin.000002恢復(fù),從134點開始到386結(jié)束?
[]
