最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

如何利用MySQL的binlog恢復(fù)誤刪數(shù)據(jù)庫(kù)詳解

 更新時(shí)間:2021年09月28日 11:32:07   作者:Honest1y  
MySQL一旦誤刪數(shù)據(jù)庫(kù)之后恢復(fù)數(shù)據(jù)很麻煩,這里記錄一下艱辛的恢復(fù)過(guò)程,這篇文章主要給大家介紹了關(guān)于如何利用MySQL的binlog恢復(fù)誤刪數(shù)據(jù)庫(kù)的相關(guān)資料,需要的朋友可以參考下

1 查看當(dāng)前數(shù)據(jù)庫(kù)內(nèi)容并備份數(shù)據(jù)庫(kù)

查看數(shù)據(jù)庫(kù)信息:

備份數(shù)據(jù)庫(kù):

[root@localhost ~]# mysqldump -u root -p t > /mnt/t.sql
Enter password: 
[root@localhost ~]# ll /mnt/t.sql 
-rw-r--r-- 1 root root 1771 Aug 25 11:56 /mnt/t.sql

2 開啟bin_log功能

首先查看數(shù)據(jù)庫(kù)是否開啟bin_log功能

mysql> show variables like "%log_bin%";

需要修改mysql的配置文件,/etc/的my.cnf,添加一句log_bin = mysql_bin即可

3 模擬誤操作(插入3條數(shù)據(jù),刪除數(shù)據(jù)庫(kù))

mysql> insert into t1 values (3);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t1 values (4);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t1 values (5);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+------+
| id   |
+------+
|    1 |
|    2 |
|    5 |
|    4 |
|    3 |
+------+
5 rows in set (0.00 sec)

mysql> flush logs;
Query OK, 0 rows affected (0.00 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql_bin.000003 |      106 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

刪除數(shù)據(jù):

mysql> truncate t1;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from t1;
Empty set (0.00 sec)

此時(shí)突然數(shù)據(jù)庫(kù)損壞或者人為刪除

mysql> drop table t1;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
Empty set (0.00 sec)

4 數(shù)據(jù)恢復(fù)

1 用已經(jīng)備份的/mnt/t.sql來(lái)恢復(fù)數(shù)據(jù)

mysql> source /mnt/t.sql;
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+-------------+
| Tables_in_t |
+-------------+
| t1          |
+-------------+
1 row in set (0.00 sec)

mysql> select * from t1;
+------+
| id   |
+------+
|    1 |
|    2 |
+------+
2 rows in set (0.00 sec)

2 還有三條數(shù)據(jù)沒有恢復(fù),怎么辦。只能用bin-log來(lái)恢復(fù)

[root@localhost ~]# mysqlbinlog --no-defaults /var/lib/mysql/mysql_bin.000002 | mysql -u root -p123.com t
mysql> use t;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from t1;
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
|    5 |
+------+
5 rows in set (0.00 sec)

mysql>

5 總結(jié)

備份數(shù)據(jù)

mysqldump -uroot -p123456 test -l -F '/tmp/test.sql'
-l:讀鎖(只能讀取,不能更新)
-F:即flush logs,可以重新生成新的日志文件,當(dāng)然包括log-bin日志

查看binlog日志

mysql>show master status;

導(dǎo)入之前備份數(shù)據(jù)

mysql -uroot -p t -v -f </mnt/t.sql
-v查看導(dǎo)入的詳細(xì)信息
-f是當(dāng)中間遇到錯(cuò)誤時(shí),可以skip過(guò)去,繼續(xù)執(zhí)行下面的語(yǔ)句

恢復(fù)binlog-file二進(jìn)制日志文件

mysqlbinlog --no-defaults binlog-file | mysql -uroot -p t

從某一(367)點(diǎn)開始恢復(fù)

mysqlbinlog --no-defaults --stop-position="367" mysql-bin.000001| mysql -uroot -p t

先查好那一點(diǎn),用more來(lái)查看

[root@localhost mysql]# /usr/bin/mysqlbinlog --no-defaults mysql-bin.000002 --start-position="794" --stop-position="1055" | more

然后恢復(fù)

[root@localhost mysql]# /usr/bin/mysqlbinlog --no-defaults mysql-bin.000002 --start-position="794" --stop-position="1055" | /usr/bin/mysql -uroot -p t

重置binlog日志

mysql> reset master;
Query OK, 0 rows affected (0.01 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      106 |              |                  |
+------------------+----------+--------------+------------------+
mysql> flush logs;#關(guān)閉當(dāng)前的二進(jìn)制日志文件并創(chuàng)建一個(gè)新文件,新的二進(jìn)制日志文件的名字在當(dāng)前的二進(jìn)制文件的編號(hào)上加1。

到此這篇關(guān)于如何利用MySQL的binlog恢復(fù)誤刪數(shù)據(jù)庫(kù)的文章就介紹到這了,更多相關(guān)MySQL binlog恢復(fù)誤刪數(shù)據(jù)庫(kù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

韶山市| 原阳县| 玉树县| 靖远县| 温州市| 佛坪县| 和政县| 西安市| 怀仁县| 霍城县| 卢湾区| 鄂伦春自治旗| 育儿| 古浪县| 牟定县| 郑州市| 双城市| 寿宁县| 林口县| 清徐县| 青阳县| 南涧| 屏山县| 修武县| 湟源县| 大埔县| 龙泉市| 宕昌县| 宝清县| 巫山县| 靖安县| 报价| 乐陵市| 海晏县| 鹤岗市| 乐业县| 荃湾区| 团风县| 天柱县| 鹤庆县| 清镇市|