CentOS7启动MySQL 5.7失败求助(附报错日志)
Hey folks, let's tackle this MySQL 5.7 startup issue on your CentOS 7 system. Looking at your logs, the key red flags are these lines (the postfix/sshd entries are likely unrelated to the MySQL failure):
Mar 30 11:08:41 my_hostname mysqld[381961]: Initialization of mysqld failed: 0
Mar 30 11:08:41 my_hostname systemd[1]: mysqld.service: control process exited, code=exited status=1
Mar 30 11:08:41 my_hostname systemd[1]: Failed to start MySQL Server. -- Subject: Unit mysqld.service has failed
Here are some practical troubleshooting steps to get your MySQL instance up and running:
Verify Data Directory Permissions
MySQL requires proper ownership and permissions on its data directory (default path:/var/lib/mysql). Run these commands to check and fix permissions:# Check current permissions ls -ld /var/lib/mysql # Set correct ownership if needed chown -R mysql:mysql /var/lib/mysql # Set secure directory permissions chmod -R 755 /var/lib/mysqlAvoid using
777permissions—they're a security risk and can actually cause issues with MySQL's permission checks.Inspect MySQL's Detailed Error Log
The systemd logs only give a high-level failure message. MySQL's own error log (usually at/var/log/mysqld.log) will have the root cause. Run this to get the latest entries:tail -n 50 /var/log/mysqld.logLook for specific errors like "Permission denied", "Can't create file", or "InnoDB initialization failed"—these will point you directly to the problem.
Check for Invalid my.cnf Configurations
A typo or misconfigured parameter in/etc/my.cnfcan break initialization. Try temporarily using the default configuration to test:# Backup your current config mv /etc/my.cnf /etc/my.cnf.bak # Attempt to start MySQL with default settings systemctl start mysqldIf it starts successfully, you can incrementally add back your custom configs to find the problematic line.
Verify Disk Space Availability
A full disk where MySQL's data directory resides will prevent initialization. Check disk usage with:df -hIf the partition for
/var/lib/mysqlis full, free up space or expand the partition before retrying.Re-initialize MySQL (If Needed)
If the initial setup failed and left corrupted files in the data directory, re-initializing can help:# Stop the service first systemctl stop mysqld # Clear existing data directory (backup first if you have important data!) rm -rf /var/lib/mysql/* # Re-initialize MySQL mysqld --initialize --user=mysql # Start the service again systemctl start mysqldAfter initialization, check
/var/log/mysqld.logfor the auto-generated temporary root password—you'll need this to log in and set a new password.Check SELinux Restrictions
CentOS 7's default SELinux enforcing mode might block MySQL from accessing files. Temporarily disable SELinux to test:setenforce 0If MySQL starts successfully, restore SELinux and apply the correct context to the data directory:
setenforce 1 chcon -R -t mysqld_db_t /var/lib/mysql
Give these steps a shot, and let us know if you find the specific error from the mysqld.log—we can dive deeper if needed!
内容的提问来源于stack exchange,提问作者Cristiano Kubiaki

