MariaDB/MySQL服务频繁启动失败求助:附报错日志详情
MariaDB/MySQL反复启停故障排查与修复方案
故障现象
- MariaDB/MySQL服务频繁无法启动,重启服务器后1-2天会再次复发
- 网站加载时提示
Error establishing database connection - 服务启动报错日志:
=============== Service Error (XID fseu38) The “mysql” service failed to start. Startup Log Starting MariaDB.230914 21:53:41 mysqld_safe Logging to '/var/lib/mysql/gla.glassheadz.com.err'. 230914 21:53:41 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql .........../etc/init.d/mysql: line 264: kill: (31815) - No such process ERROR! =================
- 关联启动脚本代码片段(对应第64行所在函数):
wait_for_ready () { i=0 while test $i -ne $service_startup_timeout ; do if $bindir/mysqladmin ping >/dev/null 2>&1; then log_success_msg return 0 elif kill -0 $! ; then : # mysqld_safe is still running else # mysqld_safe is no longer running, abort the wait loop break fi echo $echo_n "."$echo_c" i=`expr $i + 1` sleep 1 done
- 核心错误日志片段:
2023-09-01 2:04:42 0 [ERROR] mysqld: Can't lock aria control file '/var/lib/mysql/aria_log_control' for exclusive use, error: 11. Will retry for 30 seconds 2023-09-01 2:05:13 0 [ERROR] mysqld: Got error 'Could not get an exclusive lock; file is probably in use by another process' when trying to use aria control file '/var/lib/mysql/aria_log_control' 2023-09-01 2:05:13 0 [ERROR] Plugin 'Aria' init function returned error. 2023-09-01 2:05:13 0 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed. 2023-09-01 2:05:13 0 [ERROR] InnoDB: Cannot open datafile for read-only: './meta01_hemp/wp_commentmeta.ibd' OS error: 71 2023-09-01 2:05:13 0 [ERROR] InnoDB: Could not find a valid tablespace file for ``meta01_hemp`.`wp_commentmeta``. 2023-09-01 2:05:13 0 [Warning] InnoDB: Ignoring tablespace for `meta01_hemp`.`wp_commentmeta` because it could not be opened. 2023-09-01 2:05:13 0 [ERROR] Aria engine is not enabled or did not start. The Aria engine must be enabled to continue as mysqld was configured with --with-aria-tmp-tables 2023-09-01 2:05:13 0 [ERROR] Aborting
排查与修复步骤
1. 解决Aria引擎锁冲突
- 强制终止所有MySQL/MariaDB相关进程:
ps aux | grep mysql | grep -v grep | awk '{print $2}' | xargs kill -9 - 删除Aria锁文件与日志:
rm -f /var/lib/mysql/aria_log_control /var/lib/mysql/aria_log.* - 修复Aria表:
myisamchk --force --recovery /var/lib/mysql/*.MYI
2. 处理InnoDB表空间问题
- 检查缺失的表文件状态:
ls -l /var/lib/mysql/meta01_hemp/wp_commentmeta.ibd- 若文件丢失:从备份恢复该表的
ibd和frm文件;无备份时可临时跳过损坏表:- 编辑
/etc/my.cnf(或对应配置文件),添加:innodb_force_recovery = 1 - 启动服务后删除损坏表:
DROP TABLE meta01_hemp.wp_commentmeta; - 移除
innodb_force_recovery配置,重启服务后重新创建表(WordPress环境可通过重装组件或手动建表恢复)。
- 编辑
- 若文件存在但权限错误:修正属主与权限:
chown mysql:mysql /var/lib/mysql/meta01_hemp/wp_commentmeta.ibd chmod 660 /var/lib/mysql/meta01_hemp/wp_commentmeta.ibd
- 若文件丢失:从备份恢复该表的
3. 修复启动脚本容错问题
启动脚本中kill -0 $!报错是因为mysqld_safe进程已退出,修改wait_for_ready函数增加容错:
wait_for_ready () { i=0 while test $i -ne $service_startup_timeout ; do if $bindir/mysqladmin ping >/dev/null 2>&1; then log_success_msg return 0 elif [ -n "$!" ] && kill -0 $! 2>/dev/null ; then : # mysqld_safe is still running else # mysqld_safe is no longer running, abort the wait loop break fi echo -n "." i=$(expr $i + 1) sleep 1 done
4. 预防复发措施
- 定期备份数据库及表空间文件
- 监控服务器磁盘空间,避免因磁盘满导致文件损坏
- 升级MariaDB至稳定版本,修复已知引擎bug
- 配置服务监控,异常时自动触发基础排查脚本
内容的提问来源于stack exchange,提问作者user2510689
相关产品推荐
相关产品推荐

