You should try to restart MySQL service after performing each step to check if the error is solved.
But first, take a full backup of MySQL data directory /var/lib/mysql/ before you make any changes to MySQL service.
- Connect to your server via SSH as root user and restart MySQL manually. Sometimes restarting the MySQL server may fix this issue. You can use either of the following command to restart MySQL server.
/etc/init.d/mysql restart
or
service mysql restart
- You need to check whether the MySQL service is already running. If MySQL service is already running, you will have to kill them and start again. Use the following command to check if there is a MySQL service running already.
ps -aux | grep -i mysql
If MySQL service is already running, you will get list of MySQL processes with PIDs. The PID is the process ID of the MySQL processes. You will have to kill those processes.
kill -9 PID
PID – Process ID of the MySQL process.
- Check the ownership of MySQL data directory /var/lib/mysql/. Use the following command to check ownership of MySQL service
ll -aF /var/lib/mysql/
If it’s owner is root, you should change the ownership to MySQL or your user by using the following command.
chown -R mysql /var/lib/mysql/
- Take a backup of mysql.sock file and remove it. To achieve this, use the following commands:
cp /var/lib/mysql.sock /var/lib/mysql.sock_bkp
rm -rf /var/lib/mysql.sock
- Remove MySQL configuration file /etc/my.cnf or just back it up for now and restart:
mv /etc/my.cnf /etc/my.cnf.bak
- Remove the log file named ib_logfile in the MySQL data directory /var/lib/mysql/ or just back it up now and restart the MySQL service. Sometimes MySQL service fails to start when it faces difficulty in updating the log files. The log files will be created automatically once you restart the MySQL service. Use the following command to remove the log files and back it up.
Change the present working directory to MySQL data directory.
cd /var/lib/mysql
Backup and remove the log files by renaming them.
mv ib_logfile0 ib_logfile0.bak
mv ib_logfile1 ib_logfile1.bak
Move the backups to a temporary location.
mv /var/lib/mysql/ib_logfile* /tmp/folder/
- Find the log files with suffix “.err” in the MySQL data directory /var/lib/mysql/. These files contain the actual error message. You can use any editor or command like cat, less to read the error message from the log files.
cat /var/lib/mysql/yourservername.err
In many cases, MySQL will run soon after removing this error files.
rm -rf /var/lib/mysql/yourservername.err
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…