How to Fix the Error “MySQL is running but PID file could not be found”

One of our clients in Vietnam, his name is Son Vu, who is developing a website running on VPS (his homepage trainghiemmuasam.com) encountered an error that MySQL could not start, so when accessing the WordPress website, it appeared. "Error Establishing a Database Connection" error message.

When testing the MySQL service he also encountered the same message as follows:

 
[root@vpshostus mysql]# service mysql status

ERROR! MySQL is running but PID file could not be found

There are many causes for this error. Initially, we also spent a few hours trying to fix this error, but it still didn't work.

We finally found out that the problem was because the hard drive was full, so MySQL could not create the PID file, so the above error message occurred.

[root@vpshostus mysql]# df -h

Filesystem         Size  Used Avail Use% Mounted on
/dev/ploop23644p1   15G   15G     0 100% /
none               256M  4.0K  256M   1% /dev
none               256M     0  256M   0% /dev/shm

If you encounter a similar problem, first, check the hard drive space to see if there is a problem. If the space is full, just simply find the largest files on the VPS storage and delete them.

In case the error is not caused by the lack of hard drive space, try to refer to the instructions below. We find the "PID" that "mysql process" is running and kill it.

[root@vpshostus mysql]# ps aux | grep mysql
root      7766  0.2  0.3  11444  1640 pts/0    S    15:45   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql/ --pid-file=/var/lib/mysql//vpshostus.pid
mysql    11954  8.0 10.7 584184 56268 pts/0    Sl   15:47   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql/ --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/home/vpshostus.com/logs/mysql.log --open-files-limit=65536 --pid-file=/var/lib/mysql//vpshostus.pid --socket=/var/lib/mysql/mysql.sock
root     11974  0.0  0.1   6444   704 pts/0    S+   15:47   0:00 grep mysql

[root@vpshostus mysql]# kill -9 7766

[root@vpshostus mysql]# ps aux | grep mysql
root     12081  0.0  0.1   6444   704 pts/0    S+   15:47   0:00 grep mysql

Create the corresponding PID file and then restart MySQL. You're all set!

Please try it out!

In addition, the cause of the MySQL service automatically stopping is usually due to the server's lack of RAM. Therefore, you should follow 3 steps below to avoid this problem.

  • Optimize the website cache
  • Enable SWAP if not created
  • Finally, upgrade the RAM

We hope you will find this article useful. Thanks for reading!

Leave a Reply

Your email address will not be published.