k8s集群下mysql容器更换pvc存储迁移数据,报错InnoDB: Your database may be corrupt

一、背景:

在业务生产环境维护过程中会出现k8s集群下mysql容器需要更换pvc存储的场景,更换pvc存储就必须得做数据迁移,不然会出现业务数据丢失的情况。实施的方案主要有两种:

方案一:
1、将需要迁移的mysql容器里的数据通过mysqldump的方式导出来;
2、然后更换pvc存储,然后通过source 数据文件.sql的方式导入到新的数据库中;
方案二:

1、先新建pvc存储,然后挂载到mysql容器中的另一个目录上;
2、然后在容器里将mysql的数据复制到新的pvc存储挂载的目录上,修改权限和属主;

3、替换旧的pvc存储,然后mysql容器;

二、实施mysql容器数据迁移:

这里主要选择是方案二的操作。

1、创建新的pvc存储:

2、在mysql容器上挂载新pvc存储:

 

这里是将新pvc存储挂载mysql容器的/mnt目录下,记得生效容器配置。 

3、登入到mysql容器里cp迁移数据:

 cd到mysql存放数据的目录,这里默认的是/var/lib/mysql的

r
2025-10-24T06:14:45.483589Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2025-10-24T06:14:45.487190Z 0 [Note] C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe (mysqld 5.7.43-log) starting as process 2792 ... 2025-10-24T06:14:45.499521Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2025-10-24T06:14:45.500924Z 0 [Note] InnoDB: Uses event mutexes 2025-10-24T06:14:45.501775Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier 2025-10-24T06:14:45.503093Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.13 2025-10-24T06:14:45.509869Z 0 [Note] InnoDB: Number of pools: 1 2025-10-24T06:14:45.510876Z 0 [Note] InnoDB: Not using CPU crc32 instructions 2025-10-24T06:14:45.516358Z 0 [Note] InnoDB: Initializing buffer pool, total size = 4G, instances = 8, chunk size = 128M 2025-10-24T06:14:45.739511Z 0 [Note] InnoDB: Completed initialization of buffer pool 2025-10-24T06:14:45.866688Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2025-10-24T06:14:45.917325Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 1818072334033 2025-10-24T06:14:45.919665Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 1818072343203 2025-10-24T06:14:46.501026Z 0 [Note] InnoDB: Database was not shutdown normally! 2025-10-24T06:14:46.502853Z 0 [Note] InnoDB: Starting crash recovery. 2025-10-24T06:14:53.325953Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1" 2025-10-24T06:14:53.328050Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2025-10-24T06:14:53.331419Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2025-10-24T06:14:53.341449Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB. 2025-10-24T06:14:53.377635Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2025-10-24T06:14:53.379973Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2025-10-24T06:14:53.382232Z 0 [Note] InnoDB: Waiting for purge to start 2025-10-24T06:14:53.434201Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 7651ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.) 2025-10-24T06:14:53.434424Z 0 [Note] InnoDB: 5.7.43 started; log sequence number 1818072343203 2025-10-24T06:14:53.440369Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=3] log sequence number 1818075015616 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.440496Z 0 [Note] InnoDB: Loading buffer pool(s) from D:\MySql\data\ib_buffer_pool 2025-10-24T06:14:53.444882Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.454213Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=2] log sequence number 1818075015133 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.457121Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.459265Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=13] log sequence number 1818075023156 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.459333Z 0 [Note] Plugin 'FEDERATED' is disabled. 2025-10-24T06:14:53.461391Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=4] log sequence number 1818074852082 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.464302Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.468966Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=8883] log sequence number 1818075644951 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.469327Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.478059Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.481293Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=5] log sequence number 1818074822726 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.488992Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.493841Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=8] log sequence number 1818073611600 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.496594Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.499300Z 0 [ERROR] InnoDB: Page [page id: space=488, page number=3] log sequence number 1818075769646 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.500195Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=22] log sequence number 1818074006086 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.503793Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.505862Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.513791Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=23] log sequence number 1818074993296 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.515785Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.524243Z 0 [ERROR] InnoDB: Page [page id: space=488, page number=527] log sequence number 1818080514186 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.528019Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.537996Z 0 [ERROR] InnoDB: Page [page id: space=540, page number=7] log sequence number 1818081166468 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.541042Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.543656Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=31] log sequence number 1818075024348 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.548712Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.554624Z 0 [ERROR] InnoDB: Page [page id: space=540, page number=4] log sequence number 1818081150547 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.558427Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.565031Z 0 [ERROR] InnoDB: Page [page id: space=539, page number=4] log sequence number 1818080173025 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.567157Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=31683] log sequence number 1818075654250 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.567489Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.571042Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.598497Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them. 2025-10-24T06:14:53.601463Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory. 2025-10-24T06:14:53.603981Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2025-10-24T06:14:53.605450Z 0 [ERROR] InnoDB: Page [page id: space=743, page number=0] log sequence number 1818074641633 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.606048Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2025-10-24T06:14:53.609638Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. InnoDB: Dump of the tablespace extent descriptor: len 40; hex 0000000000000000ffffffff0000ffffffff000000000002aaffffffffffffffffffffffffffffff; asc ;2025-10-24T06:14:53.618233Z 0 [ERROR] InnoDB: InnoDB is trying to free page [page id: space=743, page number=8] though it is already marked as free in the tablespace! The tablespace free space info is corrupt. You may need to dump your tables and recreate the whole database! 2025-10-24T06:14:53.622034Z 0 [ERROR] [FATAL] InnoDB: Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.624235Z 0 [Warning] CA certificate ca.pem is self signed. 2025-10-24 14:14:53 0x354c InnoDB: Assertion failure in thread 13644 in file ut0ut.cc line 921 InnoDB: We intentionally generate a memory trap. InnoDB: Submit a detailed bug report to http://bugs.mysql.com. InnoDB: If you get repeated assertion failures or crashes, even InnoDB: immediately after the mysqld startup, there may be InnoDB: corruption in the InnoDB tablespace. Please refer to InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html InnoDB: about forcing recovery. 2025-10-24T06:14:53.625645Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory. 2025-10-24T06:14:53.628676Z 0 [Note] Server hostname (bind-address): '*'; port: 3308 2025-10-24T06:14:53.629979Z 0 [Note] IPv6 is available. 2025-10-24T06:14:53.630668Z 0 [Note] - '::' resolves to '::'; 2025-10-24T06:14:53.632389Z 0 [Note] Server socket created on IP: '::'. 2025-10-24T06:14:53.747077Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=16384] log sequence number 1818075741603 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.751073Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.924848Z 0 [Note] Failed to start slave threads for channel '' 2025-10-24T06:14:54.002381Z 0 [Note] Event Scheduler: Loaded 0 events 2025-10-24T06:14:54.003266Z 0 [Note] C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: ready for connections. Version: '5.7.43-log' socket: '' port: 3308 MySQL Community Server (GPL) 2025-10-24T06:14:54.063857Z 0 [ERROR] InnoDB: Page [page id: space=28, page number=0] log sequence number 1818073721575 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:54.067646Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:54.073181Z 0 [ERROR] InnoDB: Page [page id: space=28, page number=4] log sequence number 1818073721575 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:54.076879Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:54.081031Z 0 [ERROR] InnoDB: Page [page id: space=28, page number=5] log sequence number 1818073639109 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:54.083439Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:54.087366Z 0 [ERROR] InnoDB: Page [page id: space=488, page number=0] log sequence number 1818074963526 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:54.089008Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:54.840960Z 0 [Note] InnoDB: Buffer pool(s) load completed at 251024 14:14:54
最新发布
10-25
你提供的日志是 MySQL 5.7 启动过程中产生的错误信息,其中最关键的问题是: ``` InnoDB: Page [page id: space=26, page number=3] log sequence number 1818075015616 is in the future! Current system log sequence number 1818072347793. ... InnoDB: Assertion failure in thread ... [FATAL] InnoDB: Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. ``` --- ### 🔴 **问题分析** 这些错误表明: - **InnoDB数据页中的 LSN(Log Sequence Number)比当前系统的 LSN 还“新”**,也就是“来自未来”。 - 这通常意味着: ✅ 数据文件(`.ibd` 或 `ibdata1`)和事务日志文件(`ib_logfile0`, `ib_logfile1`)**不一致**。 ❌ 可能原因包括: - 非正常关机(断电、kill -9 等) - 手动复制了数据目录但没有同时复制日志文件 - 日志文件被删除或损坏 - 使用了不同时间点的数据文件与日志文件组合 此外还有这一行非常严重: ```log InnoDB: InnoDB is trying to free page [page id: space=743, page number=8] though it is already marked as free in the tablespace! The tablespace free space info is corrupt. ``` > 表空间的空闲页面管理信息已损坏 —— 这说明数据库可能已经处于**逻辑损坏状态**。 最后出现: ```log [FATAL] InnoDB: Please refer to ... forcing-innodb-recovery.html ``` MySQL 因为无法保证一致性,**拒绝继续启动并进入运行状态**(虽然后面显示 ready for connections,但实际上很多操作会失败或崩溃)。 --- ## ✅ 解决方案:强制恢复 InnoDB(Force InnoDB Recovery) 由于常规方式无法启动,需要使用 `innodb_force_recovery` 参数来尝试导出数据。 > ⚠️ 注意:此模式下禁止写操作!只能用于读取和导出数据! --- ### 🛠 步骤一:配置 `my.ini` 或 `my.cnf` 打开你的 MySQL 配置文件(Windows 通常是 `C:\ProgramData\MySQL\MySQL Server 5.7\my.ini`) 在 `[mysqld]` 段落中添加: ```ini [mysqld] innodb_force_recovery = 1 ``` > 取值范围为 1~6,数字越大恢复力度越强。建议从 1 开始尝试。 常见级别含义: | 级别 | 作用 | |------|------| | 1 (`SRV_FORCE_IGNORE_CORRUPT`) | 忽略读取损坏页的错误 | | 2 (`SRV_FORCE_NO_BACKGROUND`) | 阻止主线程和清除线程运行 | | 3 (`SRV_FORCE_NO_TRX_UNDO`) | 不执行事务回滚 | | 4 (`SRV_FORCE_NO_IBUF_MERGE`) | 禁用插入缓冲合并 | | 5 (`SRV_FORCE_NO_UNDO_LOG_SCAN`) | 不扫描 undo 日志 | | 6 (`SRV_FORCE_NO_LOG_REDO`) | 完全跳过日志重做 | --- ### 🔄 步骤二:重启 MySQL 服务 ```bash net stop mysql net start mysql ``` 观察错误日志是否允许启动,并且可以连接。 --- ### 📥 步骤三:尽快导出数据 一旦 MySQL 能够启动并接受连接,请立即使用 `mysqldump` 导出所有数据库: ```bash mysqldump -u root -p --all-databases --single-transaction > backup.sql ``` > 使用 `--single-transaction` 尽量避免锁表(但在 `innodb_force_recovery > 0` 时某些功能受限) 📌 如果遇到某个表损坏导致 dump 失败,可逐个库/表导出: ```bash mysqldump -u root -p database_name table_name > table.sql ``` --- ### 🧹 步骤四:重建数据库 1. 停止 MySQL 2. 移除整个 data 目录下的内容(备份好原文件以防万一) 3. 重新初始化 MySQL 数据目录(如果是第一次安装可用 `mysqld --initialize`) 4. 启动 MySQL 5. 导入之前导出的 SQL 文件: ```bash mysql -u root -p < backup.sql ``` --- ### ❗ 特殊情况处理 #### 如果 `innodb_force_recovery = 1` 不行,逐步提高等级: ```ini innodb_force_recovery = 2 # 再不行就试 3、4……直到能启动为止 ``` ⚠️ 当级别 ≥ 4 时,可能导致更多数据丢失,请仅用于提取关键数据。 --- ### 💾 预防措施(未来避免此类问题) 1. **确保正常关闭 MySQL** ```bash mysqladmin -u root -p shutdown ``` 2. **定期备份(推荐工具)** - `mysqldump` - `Percona XtraBackup`(热备工具) 3. **不要手动复制 `.ibd` 文件而不带日志文件** 4. **启用 `innodb_file_per_table`**,便于管理和迁移单个表 5. **监控磁盘健康、电源稳定性** --- ### 📂 关键文件位置(Windows 默认) | 文件类型 | 路径 | |--------|-----| | 配置文件 | `C:\ProgramData\MySQL\MySQL Server 5.7\my.ini` | | 数据目录 | `D:\MySql\data\` (根据日志判断) | | 错误日志 | `D:\MySql\data\*.err` 或配置指定路径 | | ibdata1 | 主共享表空间 | | ib_logfile0 / ib_logfile1 | 重做日志文件 | --- ## ✅ 总结流程 ```text 1. 添加 innodb_force_recovery=1 到 my.ini 2. 重启 MySQL 3. 成功启动后立即 mysqldump 全部数据 4. 停止 MySQL,清空 data 目录(保留配置) 5. 重新初始化数据库实例 6. 恢复 dump 出的数据 7. 移除 innodb_force_recovery 配置 8. 正常启动 ``` --- ##
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jiang0615csdn

你对鼓励是我最大的动力来源

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值