LLI Wiki — My Digital Knowledge Base

MySQL server does not start on CentOS

Diagnostic steps when a MySQL server installed on CentOS does not load its database: services, logs, data directory and error log.

On CentOS, a MySQL server can be installed but fail to load its database. These steps check the service, the system logs and the data directory settings, then read the MySQL error log.

Update the system

sudo yum -y update

Check the service and the logs

sudo systemctl list-unit-files | grep mysql
sudo journalctl -xe
sudo tail /var/log/messages
ps -ef | grep mysqld

Find the data directory and the error log

sudo cat /etc/mysql/my.cnf
egrep 'data.*dir|error.*log' /etc/my.cnf

The egrep output gives the datadir and log-error settings.

Initialize an empty data directory

On MySQL 5.7 and later, initializing an empty data directory generates a temporary root password, which is written to the error log:

sudo mysqld --initialize --user=mysql --defaults-file=/etc/my.cnf

Read the error log

If the database still does not load, read the last lines of the error log. Replace <error-log-path> with the log-error path found above:

tail -n 50 <error-log-path>

Notes

Mastodon LLIMastodon SocialFosstodon