MySQL服务突然启动不了,一种解决方法

查看mysql 错误日志显示:

2025-07-17T06:22:35.619257Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2025-07-17T06:22:35.619299Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.

2025-07-17T06:22:35.620453Z 0 [Note] C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe (mysqld 5.7.32-log) starting as process 9688 ...

2025-07-17T06:22:35.624278Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions

2025-07-17T06:22:35.624618Z 0 [Note] InnoDB: Uses event mutexes

2025-07-17T06:22:35.624787Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier 2025-07-17T06:22:35.625033Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11

2025-07-17T06:22:35.625236Z 0 [Note] InnoDB: Adjusting innodb_buffer_pool_instances from 8 to 1 since innodb_buffer_pool_size is less than 1024 MiB 2025-07-17T06:22:35.625877Z 0 [Note] InnoDB: Number of pools: 1

2025-07-17T06:22:35.626142Z 0 [Note] InnoDB: Not using CPU crc32 instructions

2025-07-17T06:22:35.631722Z 0 [Note] InnoDB: Initializing buffer pool, total size = 8M, instances = 1, chunk size = 8M

2025-07-17T06:22:35.632421Z 0 [Note] InnoDB: Completed initialization of buffer pool

2025-07-17T06:22:35.659618Z 0 [Note] InnoDB: Highest supported file format is Barracuda.

2025-07-17T06:22:35.660597Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 5442469783

2025-07-17T06:22:35.660937Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 5442480592

2025-07-17T06:22:35.661285Z 0 [ERROR] InnoDB: Ignoring the redo log due to missing MLOG_CHECKPOINT between the checkpoint 5442469783 and the end 5442480592. 2025-07-17T06:22:35.661652Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error2025-07-17T06:22:35.872505Z 0 [ERROR] Plugin 'InnoDB' init function returned error. 2025-07-17T06:22:35.872831Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.

2025-07-17T06:22:35.873059Z 0 [ERROR] Failed to initialize builtin plugins.

2025-07-17T06:22:35.873238Z 0 [ERROR] Aborting

2025-07-17T06:22:35.873369Z 0 [Note] Binlog end 2025-07-17T06:22:35.873530Z 0 [Note] Shutting down plugin 'CSV' 2025-07-17T06:22:35.873865Z 0 [Note] C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: Shutdown complete

【错误原因】

👉 **原因**:InnoDB重做日志(redo log)损坏,通常由异常关机/磁盘故障引起

### 第一步:紧急备份(必须!)
```bash
# Windows
xcopy /E /I "C:\ProgramData\MySQL\MySQL Server 5.7\Data" "D:\MySQL_Backup_%date:~0,4%%date:~5,2%%date:~8,2%"

# Linux
sudo cp -r /var/lib/mysql /backup/mysql_$(date +%Y%m%d)

【解决方法】

方法 1:尝试强制恢复模式(优先尝试)

  1. 修改配置文件(my.ini 或 my.cnf):
    在 [mysqld] 段落下添加以下配置:

    ini
     
    innodb_force_recovery = 1
  2. 启动 MySQL 服务:

    • 如果启动成功 → 立即备份数据(此时数据库为只读模式)。

    • 如果失败 → 逐步增加 innodb_force_recovery 的值(从 2 到 6),每次尝试重启服务。

      ini
       
      innodb_force_recovery = 2  # 若失败则尝试3、4、5、6

成功启动后的操作:

  1. 使用 mysqldump 备份所有数据库:

    bash
     
    mysqldump -u root -p --all-databases > full_backup.sql
  2. 移除 innodb_force_recovery 配置

 

    1. 删除损坏的重做日志文件:
      在数据目录(如 C:\ProgramData\MySQL\MySQL Server 5.7\Data)中删除以下文件:

      bash
       
      ib_logfile0
      ib_logfile1

      💡 这些文件会在 MySQL 启动时自动重建。

    2. 启动 MySQL 服务:
      若启动成功 → InnoDB 已重建日志,但可能丢失部分未提交事务(需验证数据一致性)。

 

 

posted @ 2025-07-17 15:09  xzhenqi  阅读(218)  评论(0)    收藏  举报