How to fix MySQL server PID file could not be found error

When running mysql.server related commands in your MySQL installation, you may encounter a PID file could not be found error.

The following example shows how the error appears when I ran the mysql.server stop command:

$ mysql.server status
ERROR! MySQL server PID file could not be found!

The PID file could not be found error is usually caused by two things:

  • MySQL server is not running, so no PID file was found
  • A mismatch between the running MySQL instance PID file location and the mysql.server command target location

This tutorial will help you understand both causes and how to fix them

MySQL server is not running, so no PID file was found

The MySQL PID file is a process identification file that stores the Process ID number of the running MySQL instance.

Each time you issue a command to mysql.server, MySQL would look for the PID file to find the Process ID and forward the command to the right process number.

When you start the MySQL server, the PID file is automatically generated by MySQL. When you want to stop the server, then MySQL needs to find the file to terminate the right PID from your computer.

When you run the mysql.server stop command when there’s no running MySQL instance, the response would be there’s no PID file found:

$ mysql.server stop
ERROR! MySQL server PID file could not be found!

This is why before attempting any other fix, you should make sure that the MySQL instance is running on your computer.

Depending on how you installed MySQL on your computer, you can use one of the following commands to start MySQL services:

  • mysql.service start - for MySQL installed using package managers
  • brew services start mysql - for MySQL installed with Homebrew
  • Using the preference pane for macOS official MySQL installation
  • Using the control panel for XAMPP, MAMP, or WAMP
  • Run the Windows service for MySQL from the services panel

Once you make sure that MySQL server is running, you can try the command that produces the PID file error.

If the error still appears, then it’s possible the PID file mismatch occurs on your computer. Let’s learn how to fix that next.

A MySQL service can be started from many ways: you can run the service from the Terminal or from a UI panel.

Each time you start MySQL service, the PID file is generated in a specific location depending on the configuration MySQL used.

The PID file location mismatch happens when you generate a PID file on one location, but the command you currently run seeks the PID file on another location.

In my local MySQL server, I started MySQL server using the MySQL Preference Pane that comes bundled with MySQL server installation file for Mac:

When I started the server using the Preference Pane, MySQL generates a PID file named mysqld.local.pid in the /usr/local/mysql/data/ directory.

When I tried to stop the server using mysql.server stop command, MySQL tries to find the nts-mac.pid file, which is generated if MySQL is started from the Terminal using mysql.server start command (nts-mac is the name of my Mac computer)

To fix the error, I needed to stop the currently running MySQL thread from the Preferences Pane before running the mysql.server start command again.

You may not be using MySQL Preferences Pane, but it’s possible that you have a MySQL process running in your computer or Linux server that uses a different PID file name or location than the one your command is trying to find.

If you don’t know how to stop MySQL server, then you can try to run the ps -e | grep mysql command from your terminal.

Here’s the output from my computer:

$ ps -e | grep mysql 
24836 ttys001    0:00.03 /bin/sh /usr/local/mysql/bin/mysqld_safe
24920 ttys001    0:01.04 /usr/local/mysql/bin/mysqld
24946 ttys001    0:00.01 grep mysql

The result tells me that there are running mysqld processes on my computer. If you found the same in your computer, then you need to kill the running process using one by one using the kill -9 <PID> command.

The PID code number is the first number on the left, so in my case, they are 24836 and 24920:

$ kill -9 24836
$ kill -9 24920

With that, there should be no running MySQL process on your computer. You can now try to start the MySQL server again:

$ mysql.server start
Starting MySQL
 SUCCESS!

Now that MySQL server is started from the command line, stopping the server using mysql.server stop shouldn’t cause any issue.

And those are the two ways you can fix MySQL server PID could not be found error.

If you still encounter the error, then you may need to reinstall your MySQL server. Please make sure that you save a backup of your MySQL database before you attempt to reinstall the program.

You can visit my tutorial on copying MySQL database to save a backup of your MySQL server.

I hope this tutorial helps you 👍

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.