InnoDB: Error: io_setup() failed with EAGAIN after 5 attempts

在一台服务器中以各数据库的备份文件为数据文件启动多个MySQL实例供SQL Review使用。
之前运行一直没有问题(最多的时候有23个MySQL实例同时运行),后来新配置了一台服务器,启动其对应的实例时失败。

部分错误日志如下:
……
140505 16:05:59 InnoDB: Using Linux native AIO
140505 16:05:59  InnoDB: Warning: io_setup() failed with EAGAIN. Will make 5 attempts before giving up.
InnoDB: Warning: io_setup() attempt 1 failed.
InnoDB: Warning: io_setup() attempt 2 failed.
InnoDB: Warning: io_setup() attempt 3 failed.
InnoDB: Warning: io_setup() attempt 4 failed.
InnoDB: Warning: io_setup() attempt 5 failed.
140505 16:06:02  InnoDB: Error: io_setup() failed with EAGAIN after 5 attempts.
InnoDB: You can disable Linux Native AIO by setting innodb_use_native_aio = 0 in my.cnf
140505 16:06:02 InnoDB: Fatal error: cannot initialize AIO sub-system
140505 16:06:02 [ERROR] Plugin 'InnoDB' init function returned error.
140505 16:06:02 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140505 16:06:02 [ERROR] Unknown/unsupported storage engine: InnoDB
……

通过错误日志了解到最早发生错误的地方为 InnoDB: Error: io_setup() failed with EAGAIN after 5 attempts。
这个io_setup() failed with EAGAIN是关键。

我们man一下io_setup
NAME
       io_setup - Create an asynchronous I/O context
……
DESCRIPTION
       io_setup()  creates  an asynchronous I/O context capable of receiving at least maxevents.  ctxp must not point to an AIO context that already exists, and must be 
initialized to 0
       prior to the call.  On successful creation of the AIO context, *ctxp is filled in with the resulting handle.
RETURN VALUE
       io_setup() returns 0 on success; otherwise, one of the errors listed in the "Errors" section is returned.
ERRORS
       EINVAL ctxp is not initialized, or the specified maxevents exceeds internal limits. maxevents should be greater than 0.
       EFAULT An invalid pointer is passed for ctxp.
       ENOMEM Insufficient kernel resources are available.
       EAGAIN The specified maxevents exceeds the user’s limit of available events.
       ENOSYS io_setup() is not implemented on this architecture.
CONFORMING TO
……
看到io_setup用来创建异步I/O上下文环境用于特定目的,错误代码EAGAIN意为指定的maxevents 超出了用户可用events的限制。
该服务器上已经运行了较多的MySQL实例,创建异步I/O的资源已经达到了临界,所以新的实例启动失败。

最后通过在启动MySQL实例时加入 --innodb_use_native_aio = 0解决了问题。


也有通过更改系统设置来解决此问题的(待验证)。
cat /proc/sys/fs/aio-max-nr可以查看到当前的aio-max-nr的值一般为65536(64k个)

可通过下述步骤改变该文件中的值(上述文件不能直接编辑)
sudo vim /etc/sysctl.conf
修改或加入
fs.aio-max-nr=262144(256k个)

执行命令修改/proc/sys/fs/aio-max-nr
sysctl -p

可以看到/proc/sys/fs/aio-max-nr中的值发生了变化
cat /proc/sys/fs/aio-max-nr

重启MySQL实例

还有通过修改mysql源码来避免该问题的,但一般情况下不推荐也没有必要这么做。
2025-06-19 12:25:09 7716 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace db_wcs/baglifeinfo uses space ID: 2 at filepath: .\db_wcs\baglifeinfo.ibd. Cannot open tablespace mysql/innodb_index_stats which uses space ID: 2 at filepath: .\mysql\innodb_index_stats.ibd InnoDB: Error: could not open single-table tablespace file .\mysql\innodb_index_stats.ibd InnoDB: We do not continue the crash recovery, because the table may become InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it. InnoDB: To fix the problem and start mysqld: InnoDB: 1) If there is a permission problem in the file and mysqld cannot InnoDB: open the file, you should modify the permissions. InnoDB: 2) If the table is not needed, or you can restore it from a backup, InnoDB: then you can remove the .ibd file, and InnoDB will do a normal InnoDB: crash recovery and ignore that table. InnoDB: 3) If the file system or the disk is broken, and you cannot remove InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf InnoDB: and force InnoDB to continue crash recovery here. 2025-06-19 12:25:10 9448 [Note] Plugin 'FEDERATED' is disabled. 2025-06-19 12:25:10 224c 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. 2025-06-19 12:25:10 9448 [Note] InnoDB: Using atomics to ref count buffer pool pages 2025-06-19 12:25:10 9448 [Note] InnoDB: The InnoDB memory heap is disabled 2025-06-19 12:25:10 9448 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2025-06-19 12:25:10 9448 [Note] InnoDB: Memory barrier is not used 2025-06-19 12:25:10 9448 [Note] InnoDB: Compressed tables use zlib 1.2.3 2025-06-19 12:25:10 9448 [Note] InnoDB: Not using CPU crc32 instructions 2025-06-19 12:25:10 9448 [Note] InnoDB: Initializing buffer pool, size = 8.0G 2025-06-19 12:25:10 9448 [Note] InnoDB: Completed initialization of buffer pool 2025-06-19 12:25:10 9448 [Note] InnoDB: Highest supported file format is Barracuda. 2025-06-19 12:25:10 9448 [Note] InnoDB: Log scan progressed past the checkpoint lsn 31950847983 2025-06-19 12:25:10 9448 [Note] InnoDB: Database was not shutdown normally! 2025-06-19 12:25:10 9448 [Note] InnoDB: Starting crash recovery. 2025-06-19 12:25:10 9448 [Note] InnoDB: Reading tablespace information from the .ibd files... 2025-06-19 12:25:10 9448 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace db_wcs/baglifeinfo uses space ID: 2 at filepath: .\db_wcs\baglifeinfo.ibd. Cannot open tablespace mysql/innodb_index_stats which uses space ID: 2 at filepath: .\mysql\innodb_index_stats.ibd InnoDB: Error: could not open single-table tablespace file .\mysql\innodb_index_stats.ibd InnoDB: We do not continue the crash recovery, because the table may become InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it. InnoDB: To fix the problem and start mysqld: InnoDB: 1) If there is a permission problem in the file and mysqld cannot InnoDB: open the file, you should modify the permissions. InnoDB: 2) If the table is not needed, or you can restore it from a backup, InnoDB: then you can remove the .ibd file, and InnoDB will do a normal InnoDB: crash recovery and ignore that table. InnoDB: 3) If the file system or the disk is broken, and you cannot remove InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf InnoDB: and force InnoDB to continue crash recovery here. 2025-06-19 12:25:12 7396 [Note] Plugin 'FEDERATED' is disabled. 2025-06-19 12:25:12 2484 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. 2025-06-19 12:25:12 7396 [Note] InnoDB: Using atomics to ref count buffer pool pages 2025-06-19 12:25:12 7396 [Note] InnoDB: The InnoDB memory heap is disabled 2025-06-19 12:25:12 7396 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2025-06-19 12:25:12 7396 [Note] InnoDB: Memory barrier is not used 2025-06-19 12:25:12 7396 [Note] InnoDB: Compressed tables use zlib 1.2.3 2025-06-19 12:25:12 7396 [Note] InnoDB: Not using CPU crc32 instructions 2025-06-19 12:25:12 7396 [Note] InnoDB: Initializing buffer pool, size = 8.0G 2025-06-19 12:25:12 7396 [Note] InnoDB: Completed initialization of buffer pool 2025-06-19 12:25:12 7396 [Note] InnoDB: Highest supported file format is Barracuda. 2025-06-19 12:25:12 7396 [Note] InnoDB: Log scan progressed past the checkpoint lsn 31950847983 2025-06-19 12:25:12 7396 [Note] InnoDB: Database was not shutdown normally! 2025-06-19 12:25:12 7396 [Note] InnoDB: Starting crash recovery. 2025-06-19 12:25:12 7396 [Note] InnoDB: Reading tablespace information from the .ibd files... 2025-06-19 12:25:12 7396 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace db_wcs/baglifeinfo uses space ID: 2 at filepath: .\db_wcs\baglifeinfo.ibd. Cannot open tablespace mysql/innodb_index_stats which uses space ID: 2 at filepath: .\mysql\innodb_index_stats.ibd InnoDB: Error: could not open single-table tablespace file .\mysql\innodb_index_stats.ibd InnoDB: We do not continue the crash recovery, because the table may become InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it. InnoDB: To fix the problem and start mysqld: InnoDB: 1) If there is a permission problem in the file and mysqld cannot InnoDB: open the file, you should modify the permissions. InnoDB: 2) If the table is not needed, or you can restore it from a backup, InnoDB: then you can remove the .ibd file, and InnoDB will do a normal InnoDB: crash recovery and ignore that table. InnoDB: 3) If the file system or the disk is broken, and you cannot remove InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf InnoDB: and force InnoDB to continue crash recovery here. 2025-06-19 12:25:13 1704 [Note] Plugin 'FEDERATED' is disabled. 2025-06-19 12:25:13 2d94 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. 2025-06-19 12:25:13 1704 [Note] InnoDB: Using atomics to ref count buffer pool pages 2025-06-19 12:25:13 1704 [Note] InnoDB: The InnoDB memory heap is disabled 2025-06-19 12:25:13 1704 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2025-06-19 12:25:13 1704 [Note] InnoDB: Memory barrier is not used 2025-06-19 12:25:13 1704 [Note] InnoDB: Compressed tables use zlib 1.2.3 2025-06-19 12:25:13 1704 [Note] InnoDB: Not using CPU crc32 instructions 2025-06-19 12:25:13 1704 [Note] InnoDB: Initializing buffer pool, size = 8.0G 2025-06-19 12:25:13 1704 [Note] InnoDB: Completed initialization of buffer pool 2025-06-19 12:25:13 1704 [Note] InnoDB: Highest supported file format is Barracuda. 2025-06-19 12:25:13 1704 [Note] InnoDB: Log scan progressed past the checkpoint lsn 31950847983 2025-06-19 12:25:13 1704 [Note] InnoDB: Database was not shutdown normally! 2025-06-19 12:25:13 1704 [Note] InnoDB: Starting crash recovery. 2025-06-19 12:25:13 1704 [Note] InnoDB: Reading tablespace information from the .ibd files... 2025-06-19 12:25:13 1704 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace db_wcs/baglifeinfo uses space ID: 2 at filepath: .\db_wcs\baglifeinfo.ibd. Cannot open tablespace mysql/innodb_index_stats which uses space ID: 2 at filepath: .\mysql\innodb_index_stats.ibd InnoDB: Error: could not open single-table tablespace file .\mysql\innodb_index_stats.ibd InnoDB: We do not continue the crash recovery, because the table may become InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it. InnoDB: To fix the problem and start mysqld: InnoDB: 1) If there is a permission problem in the file and mysqld cannot InnoDB: open the file, you should modify the permissions. InnoDB: 2) If the table is not needed, or you can restore it from a backup, InnoDB: then you can remove the .ibd file, and InnoDB will do a normal InnoDB: crash recovery and ignore that table. InnoDB: 3) If the file system or the disk is broken, and you cannot remove InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf InnoDB: and force InnoDB to continue crash recovery here. 这是一开始的报错日志信息,请帮忙分析报错1067的原因
最新发布
06-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值