CentOS 上 MySQL 启动失败的定位与修复步骤
一、快速定位
systemctl status mysqld 与 journalctl -xe,从输出中定位到具体错误(如权限、配置、端口、资源等)。/var/log/mysqld.log 或 /var/log/mysql/error.log,使用 tail -n50 /var/log/mysqld.log | grep -i error 快速筛查。ss -tulpen | grep 3306 或 netstat -tuln | grep 3306,确认 3306 是否被其他进程占用。free -h(内存)、df -h(磁盘),内存不足或磁盘满都会导致启动失败。二、常见原因与对应修复
systemctl status 提示控制进程退出或 Job for mysqld.service failed...。/etc/my.cnf 或 /etc/mysql/my.cnf 的语法与参数(如 datadir、port、socket),修正后 systemctl start mysqld。datadir(常见为 /var/lib/mysql)属主属组为 mysql:mysql,权限建议 750;执行:chown -R mysql:mysql /var/lib/mysql && chmod -R 750 /var/lib/mysql。The server quit without updating PID file 或 socket 锁文件异常。rm -f /tmp/mysql.sock.lock;mkdir -p /var/run/mysqld && chown -R mysql:mysql /var/run/mysqld;systemctl start mysqld。InnoDB: Ignoring the redo log due to missing MLOG_CHECKPOINT... Plugin initialization aborted。ib_logfile*,再启动:systemctl start mysqld。my.cnf 的 port 后启动。三、标准排查与修复流程
systemctl status mysqld、journalctl -xe、tail -n50 /var/log/mysqld.log | grep -i error。/etc/my.cnf 中 datadir、port、socket 等关键参数。datadir 与 /var/run/mysqld 属主为 mysql:mysql,权限 750。ib_logfile*(先备份)。free -h、df -h,确保内存与磁盘充足。systemctl start mysqld && systemctl status mysqld,确认 Active: active (running)。四、仍未恢复时的建议