MySQL

[How To] Fix "MySQL is running but PID file could not be found" error

MySQL is one of the widely used database software in the application world. Many times, one has to work on the MySQL services and restart the services for the changes made to take effect or etc...

While restarting MySQL service, you may get a error as

MySQL is running but PID file could not be found

This might be due to issues with disk space, disk inode usage or innodb corruption which may lead to the error.

In my case, the issue was with the pid file and solution was:

1) SSH server as a root user

2) Create directory /var/run/mysql

mkdir /var/run/mysql

3) Create  a file with name as mysqld.pid

touch mysqld.pid

4) Change its ownership and group to  mysql:mysql

chown mysql:mysql mysqld.pid

5) Restart MySQL service and you will see no more errors

If any feedback, queries are always welcome!

Abhijit Sandhan

Love to Automate, Blog, Travel, Hike & spread Knowledge!

Related Articles

6 Comments

  1. hello all ... i did all the setting which you mention ..but after that i my problem was as it is ..i went to panel as root and try to restart mysql services and i got lot of serious error .. i have less hand in mysql plz help ..

    Cpanel::Exception::Timeout/(XID 8qwkh9) The system failed to lock the file “/var/run/restartsrv_mysql” after 197 seconds. at /usr/local/cpanel/Cpanel/Exception/CORE.pm line 336. Cpanel::Exception::create("Timeout", "The system failed to lock the file x{e2}x{80}x{9c}[_1]x{e2}x{80}x{9d} after [quant,_2"..., ARRAY(0x2c93db8)) called at /usr/local/cpanel/Cpanel/Exception.pm line 61 Cpanel::Exception::__ANON__(__CPANEL_HIDDEN__, __CPANEL_HIDDEN__..., ARRAY(0x2c93db8)) called at /usr/local/cpanel/Cpanel/SafeFile.pm line 729 Cpanel::SafeFile::_timeout_exception("/var/run/restartsrv_mysql", 197) called at /usr/local/cpanel/Cpanel/SafeFile.pm line 761 Cpanel::SafeFile::_die_if_file_is_flocked_cuz_already_waited_a_while("/var/run/restartsrv_mysql", 197) called at /usr/local/cpanel/Cpanel/SafeFile.pm line 829 Cpanel::SafeFile::_lock_wait("/var/run/restartsrv_mysql") called at /usr/local/cpanel/Cpanel/SafeFile.pm line 355 Cpanel::SafeFile::_safelock("/var/run/restartsrv_mysql") called at /usr/local/cpanel/Cpanel/SafeFile.pm line 558 Cpanel::SafeFile::_safe_open(undef, ">>", "/var/run/restartsrv_mysql", CODE(0xb6c3c0), "safeopen") called at /usr/local/cpanel/Cpanel/SafeFile.pm line 115 Cpanel::SafeFile::safeopen(undef, ">>", "/var/run/restartsrv_mysql") called at /usr/local/cpanel/Cpanel/RestartSrv/Lock.pm line 25 Cpanel::RestartSrv::Lock::new("Cpanel::RestartSrv::Lock", "mysql") called at /usr/local/cpanel/Cpanel/ServiceManager/Base.pm line 183 Cpanel::ServiceManager::Base::lock(Cpanel::ServiceManager::Services::Mysql=HASH(0x2c901b8)) called at /usr/local/cpanel/Cpanel/ServiceManager/Base.pm line 459 Cpanel::ServiceManager::Base::BUILD(Cpanel::ServiceManager::Services::Mysql=HASH(0x2c901b8), HASH(0xb8f1a8)) called at /usr/local/cpanel/3rdparty/perl/526/lib64/perl5/cpanel_lib/x86_64-linux-64int/Cpanel/Class/Object.pm line 49 Cpanel::Class::Object::BUILDALL(Cpanel::ServiceManager::Services::Mysql=HASH(0x2c901b8), HASH(0xb8f1a8)) called at /usr/local/cpanel/3rdparty/perl/526/lib64/perl5/cpanel_lib/x86_64-linux-64int/Cpanel/Class/Object.pm line 41 Cpanel::Class::Object::new("Cpanel::ServiceManager::Services::Mysql", "service", "mysql") called at /usr/local/cpanel/Cpanel/ServiceManager.pm line 99 Cpanel::ServiceManager::new("Cpanel::ServiceManager", "service", "mysql") called at bin/restartsrv_base.pl line 79 scripts::restartsrv_base::__ANON__() called at /usr/local/cpanel/3rdparty/perl/526/lib64/perl5/cpanel_lib/Try/Tiny.pm line 99 eval {...} called at /usr/local/cpanel/3rdparty/perl/526/lib64/perl5/cpanel_lib/Try/Tiny.pm line 90 Try::Tiny::try(CODE(0x2c90740), Try::Tiny::Catch=REF(0xb5af78)) called at bin/restartsrv_base.pl line 125 scripts::restartsrv_base::run("--html", "--wait", "--verbose") called at bin/restartsrv_base.pl line 33

    1. This seems to be an issue with lock file creation. When you are starting MySQL service it is getting hanged and hence could not be restarted. The same can be deduced from the error logs.
      Please login into the shell as root user and try restarting service using command
      /scripts/restartsrv_mysql
      Check the MySQL error log for details mostly generated under /var/lib/mysql folder and take further steps accordingly.
      You can also try disabling open file limit for MySQL from WHM and increasing open file limit for MySQL manually from shell.
      If this does not solve the problem then open a support ticket at cPanel.

      Let us know the solution worked in your case.

  2. hello
    we have this problem:

    root@server [~]# service mysql start
    Starting MySQL.The server quit without updating PID file (/var/lib/mysql/server.domain.com.pid). [FAILED]

  3. Hi,
    thanks for that post.
    but my problem not resolved.
    i giving that error ( MySQL is running but PID file could not be found )
    please help me, so thanks

    1. It seems that the process is still running. Check the process id using command
      ps aufx | grep mysql*
      and kill that process using kill command
      kill -9 PID
      Try restarting MySQL service

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button