设为首页 加入收藏

TOP

简单误操作恢复(一)
2019-02-16 06:08:15 】 浏览:240
Tags:简单 操作 恢复

MySQL误操作后的恢复

场景:
1、数据库每天都有全备份。
2、数据库开启bin-log
3、准确定位误操作语句

一、 创建全备份,建议带有 --master-data=2参数
mysqldump -uroot -ppassword123 -S /data/mysqldata/3306/mysql.sock -F -R --triggers --lock-tables --master-data=2 -B test > /data/mysqldata/backup/test.$(date "+%F_%H:%M:%S").full.sql

二、正常使用数据库

[root@localhost backup]# mysql -uroot -ppassword123 -S /data/mysqldata/3306/mysql.sock
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 43
Server version: 5.6.41-log Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> 
mysql> use test6;
ERROR 1049 (42000): Unknown database 'test6'
mysql> use test
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> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t_idb_big      |
| test1          |
| test2          |
| test3          |
| test4          |
| test5          |
| test6          |
+----------------+
7 rows in set (0.00 sec)

mysql> select count from test6;
ERROR 1054 (42S22): Unknown column 'count' in 'field list'
mysql> select count(*) from test6;
+----------+
| count(*) |
+----------+
|    30161 |
+----------+
1 row in set (0.02 sec)

mysql> 
mysql> 
mysql> select count(*) from t_idb_big;
+----------+
| count(*) |
+----------+
|    30161 |
+----------+
1 row in set (0.01 sec)

mysql> 

三、发生误操作,单其他操作还在进行

mysql> 
mysql> delete from test6;
Query OK, 30161 rows affected (1.14 sec)

mysql> 
mysql> 
mysql> 
mysql> 
mysql> desc test5;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name  | char(20)         | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql> select * from test5;
+----+------+
| id | name |
+----+------+
|  3 | a    |
|  4 | b    |
+----+------+
2 rows in set (0.00 sec)

mysql> insert into test5 (name) values ('c');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test5 (name) values ('d');
Query OK, 1 row affected (0.00 sec)

mysql> select * from test5;
+----+------+
| id | name |
+----+------+
|  3 | a    |
|  4 | b    |
|  5 | c    |
|  6 | d    |
+----+------+
4 rows in set (0.00 sec)

四、发现误操作后,及时锁库,尽快修复

mysql> 
mysql> 
mysql> 
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.46 sec)

mysql> 
mysql> 
mysql> exit
Bye
[root@localhost backup]# ls -ralt
total 35940
drwxrwxr-x. 2 mysql mysql        6 Sep 15 16:14 3306
-rw-rw-r--. 1 mysql mysql  5568942 Sep 15 16:56 test_3306_2018-09-15.sql
drwxrwxr-x. 2 mysql mysql       73 Sep 15 17:27 mysql_full
drwxrwxr-x. 3 mysql mysql       50 Sep 15 18:45 mysql_full_by_dbs
drwxrwxr-x. 3 mysql mysql       18 Sep 15 19:25 mysql_full_by_tbs
-rw-r--r--  1 mysql mysql  6227100 Ja
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇mysqlnavicat编码保持一致不乱码 下一篇几种redis数据导出导入方式解析

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目