服务器断电后MySQL修复:sock文件丢失与InnoDB表恢复指南

需积分: 15 24 下载量 151 浏览量 更新于2024-09-02 收藏 4KB MD 举报
当服务器在运行MySQL服务时遭遇突然断电,重启后可能会遇到无法连接到MySQL服务器的问题,具体表现为启动时报错"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'(2)"。这通常是因为MySQL的守护进程(mysqld)在重启时无法找到用于网络通信的套接字文件(mysql.sock),这是MySQL服务器启动时的默认通信端口。 问题的核心在于InnoDB引擎的数据损坏。根据提供的错误日志,InnoDB引擎在尝试打开系统表空间(\ibdata1)时提示无法以读写模式打开,表明数据完整性遭到破坏。错误信息中提到的"InnoDB: page 417 log sequence number 2840941881 is in the future!" 表明InnoDB日志文件可能没有正确地同步到预期的位置,可能导致了数据库恢复过程中的混乱。 InnoDB引擎的警告进一步指出,如果只是复制了数据文件而没有同步日志文件,或者数据库可能已经受到严重损坏,需要进行恢复操作。它推荐访问MySQL官方文档(<http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html>)以获取更详细的恢复指南。 针对这种情况,解决方案一般分为以下几步: 1. **确认服务状态**: - 检查mysqld服务是否已经启动,如果未启动,尝试手动启动。 - 使用`sudo systemctl status mysqld` 或 `sudo service mysql status`来查看服务状态和错误日志。 2. **恢复模式**: - 如果确定服务状态异常,可以尝试将MySQL启动进入安全模式(--skip-grant-tables),以允许无权限登录,然后进行问题定位和数据恢复。 3. **定位并修复损坏的InnoDB表空间**: - 使用MySQL的`my.cnf`配置文件,通过`innodb_force_recovery`参数设置为特定值(如7或6),允许在部分损坏情况下启动服务。 - 运行`mysql`命令并执行`SHOW ENGINE INNODB STATUS`查看详细的错误和恢复建议。 4. **恢复数据**: - 根据官方文档提供的指示,可能需要手动恢复日志文件或者使用`innobackupex`工具进行备份和恢复。 - 考虑使用`mysqlhotcopy`或`pt-online-schema-change`等工具谨慎地恢复表空间。 5. **检查并修复表结构**: - 数据恢复后,检查受影响的InnoDB引擎表结构,可能需要重建日志文件或使用`REPAIR TABLE`语句修复损坏的表。 6. **恢复和优化**: - 在确保数据恢复完整后,重新设置`innodb_force_recovery`参数为0,让MySQL在正常模式下运行,并监控其性能,如有必要,调整参数以防止类似问题再次发生。 面对这样的问题,关键步骤是正确诊断和恢复InnoDB引擎的损坏,同时确保数据的安全性和完整性。在处理过程中,务必小心谨慎,遵循官方文档的指引,并在必要时寻求专业人员的帮助。
2017-11-15 上传
处理一下出现的日志 Plugin 'FEDERATED' is disabled. 2017-11-15 19:23:46 16c0 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator. 2017-11-15 19:23:46 1404 [Note] InnoDB: Using atomics to ref count buffer pool pages 2017-11-15 19:23:46 1404 [Note] InnoDB: The InnoDB memory heap is disabled 2017-11-15 19:23:46 1404 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2017-11-15 19:23:46 1404 [Note] InnoDB: Memory barrier is not used 2017-11-15 19:23:46 1404 [Note] InnoDB: Compressed tables use zlib 1.2.3 2017-11-15 19:23:46 1404 [Note] InnoDB: Not using CPU crc32 instructions 2017-11-15 19:23:46 1404 [Note] InnoDB: Initializing buffer pool, size = 9.0G 2017-11-15 19:23:46 1404 [Note] InnoDB: Completed initialization of buffer pool 2017-11-15 19:23:46 1404 [Note] InnoDB: Highest supported file format is Barracuda. 2017-11-15 19:23:46 1404 [Note] InnoDB: Log scan progressed past the checkpoint lsn 9219742510 2017-11-15 19:23:46 1404 [Note] InnoDB: Database was not shutdown normally! 2017-11-15 19:23:46 1404 [Note] InnoDB: Starting crash recovery. 2017-11-15 19:23:46 1404 [Note] InnoDB: Reading tablespace information from the .ibd files... 2017-11-15 19:23:46 1404 [Note] InnoDB: Restoring possible half-written data pages 2017-11-15 19:23:46 1404 [Note] InnoDB: from the doublewrite buffer... InnoDB: Doing recovery: scanned up to log sequence number 9219763629 InnoDB: 1 transaction(s) which must be rolled back or cleaned up InnoDB: in total 0 row operations to undo InnoDB: Trx id counter is 275040768 2017-11-15 19:23:47 1404 [Note] InnoDB: Starting an apply batch of log records to the database... InnoDB: Progress in percent: 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 InnoDB: Apply batch completed 2017-11-15 19:23:48 1404 [Note] InnoDB: 128 rollback segment(s) are active. InnoDB: Starting in background the rollback of uncommitted transactions 2017-11-15 19:23:48 fc8 InnoDB: Rolling back trx with id 275035944, 0 rows to undo 2017-11-15 19:23:48 fc8 InnoDB: Assertion failure in thread 4040 in file fut0lst.ic line 83 InnoDB: Failing assertion: addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA 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.6/en/forcing-innodb-recovery.html InnoDB: about forcing recovery. 2017-11-15 19:23:48 1404 [Note] InnoDB: Waiting for purge to start 2017-11-15 19:23:48 1404 [Note] InnoDB: 5.6.21 started; log sequence number 9219763629 2017-11-15 19:23:48 1404 [Note] Server hostname (bind-address): '*'; port: 3306 2017-11-15 19:23:48 1404 [Note] IPv6 is available. 2017-11-15 19:23:48 1404 [Note] - '::' resolves to '::'; 2017-11-15 19:23:48 1404 [Note] Server socket created on IP: '::'. 2017-11-15 19:23:48 1404 [Note] Event Scheduler: Loaded 0 events 2017-11-15 19:23:48 1404 [Note] D:\Documents\mysql\bin\mysqld.exe: ready for connections. Version: '5.6.21' socket: '' port: 3306 MySQL Community Server (GPL)