千家信息网

mysql数据库恢复操作指南

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,下文给大家带来有关mysql数据库恢复操作指南内容,相信大家一定看过类似的文章。我们给大家带来的有何不同呢?一起来看看正文部分吧,相信看完mysql数据库恢复操作指南你一定会有所收获。1、系统说明:数
千家信息网最后更新 2026年11月01日mysql数据库恢复操作指南

下文给大家带来有关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数据库恢复操作指南,大家觉得是自己想要的吗?如果想要了解更多相关,可以继续关注我们的行业资讯板块。


数据 数据库 日志 文件 指南 操作指南 更新 测试 重要 国民 国民党 条件 系统 巴顿 胡适 蒋介石 不同 成功 操作系统 一行 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 没上市的科技互联网公司 科技制造互联网公司 易互联网科技有限公司 互联网金融 金融科技 友谊互联网络科技 华中科技有哪些互联网大佬 现代互联网科技股 福建科技产业互联网发展 江阴互联网智能科技产品进口 华夏恒生科技与互联网科技 互联网金融科技公司的优势 南通创西澳互联网科技有限公司 雨阳互联网卡科技有限公司 西安有哪些互联网高科技企业 珠海东科互联网科技有限公司 科技和互联网行业的特点 盐城市攀科互联网科技有限公司 数字科技和互联网金融哪个好 广东猫王互联网科技有限公司电话 互联网科技创新方面的资料 互联网科技工作委员会副主任毛军 上海挚品互联网科技 浩特互联网科技 四川狮子座互联网科技 互联网科技股午盘股票涨跌 恒生科技互联网指数分析 玖二柒互联网科技公司待遇 保险科技服务互联网营销体系 风投北京互联网科技 科技互联网专业务虚会材料
0