mysql backup table_MySQL 常见的几种恢复------table的删除(有备份情况)

本文详细介绍了在MySQL中误删除表后的恢复步骤,包括使用mysqldump进行全备,查找binlog定位删除操作,以及如何通过binlog回滚到删除前的状态,最终成功恢复数据。
摘要由CSDN通过智能技术生成

1.误删除表的恢复

测试:mysqldump -uroot -p123 -A -B --events --master-data=2 --single-transaction >/tmp/sql全备

一。删除表

mysql> show tables;

+---------------+

| Tables_in_liu |

+---------------+

| t1 |

| t2 |

| t3 |

| t4 |

+---------------+

mysql> desc t2;

+-----------+-------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+-----------+-------------+------+-----+---------+----------------+

| test_code | int(11) | NO | PRI | NULL | auto_increment |

| name | varchar(20) | YES | | NULL | |

+-----------+-------------+------+-----+---------+----------------+

2 rows in set (0.00 sec)

mysql> insert into t2 (name) values('aa');

Query OK, 1 row affected (5.06 sec)

mysql> drop table t2;

Query OK, 0 rows affected (0.06 sec)

mysql> select * from t2;

ERROR 1146 (42S02): Table 'liu.t2' doesn't exist

mysql>

mysql> use test;

Database changed

mysql> show tables;

+----------------+

| Tables_in_test |

+----------------+

| a |

| li |

| user |

| xiaobai |

| xiaohe |

+----------------+

5 rows in set (0.00 sec)

mysql> select * from a;

+----+------+

| a | b |

+----+------+

| 1 | 1 |

| 3 | 1 |

| 5 | 3 |

| 7 | 6 |

| 10 | 8 |

+----+------+

5 rows in set (0.00 sec)

mysql> drop table a;

Query OK, 0 rows affected (0.10 sec)

mysql> select * from a;

ERROR 1146 (42S02): Table 'test.a' doesn't exist

+----+------+

| id | name |

+----+------+

| 2 | b |

+----+------+

1 row in set (0.00 sec)

mysql> insert into li(id,name) values(3,'c');

Query OK, 1 row affected (0.10 sec)

mysql> commit;

Query OK, 0 rows affected (0.00 sec)

mysql> drop table li;

Query OK, 0 rows affected (0.05 sec)

二,找binglog

mysqlbinlog --start-datetime='2020-07-08 19:00:00'  --stop-datetime='2020-07-08 20:00:00' -d liu mysql-bin.000001

mysqlbinlog  mysql-bin.000001 |grep -5a "DROP TABLE"

三。

执行drop 之前pos

四恢复数据库

mysql> show tables;

+----------------+

| Tables_in_test |

+----------------+

| a |

| li |

| t4 |

| user |

| xiaobai |

| xiaohe |

+----------------+

6 rows in set (0.00 sec)

mysql> select * from li;

+----+------+

| id | name |

+----+------+

| 2 | b |

+----+------+

1 row in set (0.00 sec)

5.恢复drop之前的修改

mysql> source /tmp/li.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)

Charset 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)

Query OK, 0 rows affected, 1 warning (0.00 sec)

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.10 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)

mysql> select * from li;

+----+------+

| id | name |

+----+------+

| 2 | b |

| 3 | c |

+----+------+

2 rows in set (0.00 sec)

mysql>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值