mysql数据库恢复操作指南
admin
2023-05-28 05:21:10
0

下文给大家带来有关mysql数据库恢复操作指南内容,相信大家一定看过类似的文章。我们给大家带来的有何不同呢?一起来看看正文部分吧,相信看完mysql数据库恢复操作指南你一定会有所收获。

1、系统说明:

数据库版本:MySql5.6.34

操作系统:CentOS release 6.8 (Final)

数据库编码:utf8

数据库故障描述:测试库中更新某个字段,但是没有加where 条件,导致某个列全部更新为同一值。

select * from test

    -> ;

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

| id | name     |

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

|  1 | 孙立人    |

|  2 | 薛岳      |

|  3 | 李宗仁    |

|  4 | ×××      |

|  5 | 白崇禧    |

|  6 | 廖耀湘    |

|  7 | 巴顿      |

|  8 | 蒋介石    |

|  9 | 国民党    |

| 10 | 胡适      |

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

10 rows in set (0.00 sec)

 

update test set name ='×××';

Query OK, 10 rows affected (0.01 sec)

Rows matched: 10 Changed: 10  Warnings: 0

 

mysql> select * from test;

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

| id | name     |

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

|  1 | ×××    |

|  2 | ×××    |

|  3 | ×××    |

|  4 | ×××    |

|  5 | ×××    |

|  6 | ×××    |

|  7 | ×××    |

|  8 | ×××    |

|  9 | ×××    |

| 10 | ×××    |

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

10 rows in set (0.00 sec)

2、查看binlog日志是否开启:

在my.cnf中的[mysqld]域中

看到已经开启日志:

 

[mysqld]

 

# Remove leading # and set to the amount of RAM forthe most important data

# cache in MySQL. Start at 70% of total RAM fordedicated server, else 10%.

# innodb_buffer_pool_size = 128M

 

# Remove leading # to turn on a very important dataintegrity option: logging

# changes to the binary log between backups.

# log_bin

log_bin=mysqlbin_oldboy

3、查看数据库存放位置中的日志文件:

cd /data/mysql

-rw-rw----. 1 mysql mysql       56 1月  20 00:14 auto.cnf

-rw-r--r--. 1 root root      4412 2月   8 16:05 bintest.sql

-rw-rw----. 1 mysql mysql 12582912 2月   8 16:06 ibdata1

-rw-rw----. 1 mysql mysql 50331648 2月   8 16:06 ib_logfile0

-rw-rw----. 1 mysql mysql 50331648 1月  20 00:13 ib_logfile1

drwx------. 2 mysql mysql     4096 1月  20 00:14 mysql

-rw-rw----. 1 mysql mysql     3068 2月   8 16:06mysqlbin_oldboy.000001

-rw-rw----. 1 mysql mysql       25 2月   8 00:45 mysqlbin_oldboy.index

srwxrwxrwx. 1 mysql mysql        0 2月   8 00:45 mysql.sock

drwx------. 2 mysql mysql     4096 2月   7 22:58 oldboy

drwx------. 2 mysql mysql     4096 2月   7 22:39 oldgirl

drwx------. 2 mysql mysql     4096 1月  20 00:14 performance_schema

drwx------. 2 mysql mysql     4096 2月   8 00:17 test

-rw-r-----. 1 mysql root     44363 2月   8 15:42 web1.err

-rw-rw----. 1 mysql mysql        7 2月   8 00:45 web1.pid

 

标红地方就是我们要使用的日志文件。

使用mysqlbinlog命令把mysqlbin_oldboy.000001转换成sql文件,

mysqlbinlog -d test mysqlbin_oldboy.000001>bin.sql

说明:-d 指定数据库

[root@web1 mysql]# ll

总用量 110696

-rw-rw----. 1 mysql mysql       56 1月  20 00:14 auto.cnf

-rw-r--r--. 1 root  root     7707 2月   8 16:28 bin.sql

-rw-r--r--. 1 root root      4412 2月   8 16:05 bintest.sql

-rw-rw----. 1 mysql mysql 12582912 2月   8 16:25 ibdata1

-rw-rw----. 1 mysql mysql 50331648 2月   8 16:25 ib_logfile0

-rw-rw----. 1 mysql mysql 50331648 1月  20 00:13 ib_logfile1

drwx------. 2 mysql mysql     4096 1月  23 22:50 mydx

drwx------. 2 mysql mysql     4096 1月  20 00:14 mysql

-rw-rw----. 1 mysql mysql     3285 2月   8 16:25 mysqlbin_oldboy.000001

-rw-rw----. 1 mysql mysql       25 2月   8 00:45 mysqlbin_oldboy.index

srwxrwxrwx. 1 mysql mysql        0 2月   8 00:45 mysql.sock

drwx------. 2 mysql mysql     4096 2月   7 22:58 oldboy

drwx------. 2 mysql mysql     4096 2月   7 22:39 oldgirl

drwx------. 2 mysql mysql     4096 1月  20 00:14 performance_schema

drwx------. 2 mysql mysql     4096 2月   8 00:17 test

-rw-r-----. 1 mysql root     44363 2月   8 15:42 web1.err

-rw-rw----. 1 mysql mysql        7 2月   8 00:45 web1.pid

 

编辑bin.sql文件

vim bin.sql

         

# at 3147

#170208 16:25:52 server id 1  end_log_pos 3254 CRC32 0xa4ab5836         Query   thread_id=2     exec_time=0     error_code=0

SET TIMESTAMP=1486542352/*!*/;

update test set name ='×××'       删除这一行

/*!*/;

# at 3254

                   

然后进行恢复:

[root@web1 mysql]# mysql -uroot -p test -e"select * from test;"

Enter password:

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

| id | name     |

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

|  1 | ×××    |

|  2 | ×××    |

|  3 | ×××    |

|  4 | ×××    |

|  5 | ×××    |

|  6 | ×××    |

|  7 | 巴顿      |

|  8 | 蒋介石    |

|  9 | 国民党    |

| 10 | 胡适      |

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

 

之所以看到1-6还是×××,那是因为我之前没有开启binlog日志,现在看到mysql开启日志的重要性了吧!

 

总结:

mysql数据更新的时候一定要带上where条件,一定要在测试库上测试成功之后再进行操作,数据是一个公司的最重要的文件,请一定要重视。

对于上文关于mysql数据库恢复操作指南,大家觉得是自己想要的吗?如果想要了解更多相关,可以继续关注我们的行业资讯板块。


相关内容

热门资讯

全链条培育科技型企业,河南擘画... 【大河财立方 记者 张克瑶】河南科技型企业再获全生命周期全链条支持。近日,河南省科技厅会同省委金融办...
俄罗斯总统普京访华期间两国元首... 新华社北京5月20日电俄罗斯总统普京访华期间两国元首会晤成果文件清单一、请两国元首签署并发表的文件《...
免费抽蒜薹 这账怎么“蒜” 打捆出售的蒜薹。孟亚威 摄5月5日,在河南省开封市鼓楼区仙人庄街道杨岗村,农民在田间收获大蒜。新华社...
几首词勾勒出千年宋韵,一部剧道... 杨洋饰演的展昭 图片来源:电视剧《雨霖铃》官方微博大宋御河景区呈现古之汴河风貌 图片来源:汴河游船公...
IPO“静默期”遭自媒体精准围... 近日,最高人民检察院披露了一起财经自媒体假借“舆论监督”之名,精准围猎拟上市企业的敲诈勒索案。据了解...
风声|AI狂奔全民分钱,有可能... 作者丨刘正Simon Kucher 战略咨询顾问从某种意义上说,韩国,这个“东亚怪物房吊车尾,内卷文...
中华人民共和国和俄罗斯联邦关于... 新华社北京5月20日电中华人民共和国和俄罗斯联邦关于进一步加强全面战略协作、深化睦邻友好合作的联合声...
奋力走好革命老区乡村振兴先行路... 光山“环龙山湖”宜居宜业和美乡村先导区一隅。史霞 摄寒羽尚服饰工人正在裁剪下料。刘一兵 摄光山县建起...
从濮阳到重庆,跨越1400公里... 汉寨外村村民为陈鹏(左二)送上一束“麦穗花”,表达欢迎与感谢。刘冬 摄5月19日,时近小满节气,河南...
国家组织冠脉支架接续采购落地,... 新华社天津5月20日电(记者彭韵佳、栗雅婷)“国家组织冠脉支架集中带量采购”第二轮接续采购20日在天...