Troubleshooting “MySQL Server PID File Could Not Be Found” Error on macOS


1 views

When working with MySQL on macOS, you might encounter the frustrating situation where the server appears to start successfully (SUCCESS! message), but subsequent operations fail with the error:

ERROR! MySQL server PID file could not be found!

This typically indicates that while the MySQL daemon process is running, the system cannot locate the Process ID (PID) file that should contain the server's process information.

On macOS, MySQL typically stores its PID file in one of these locations:

/usr/local/var/mysql/hostname.pid
/var/run/mysqld/mysqld.pid
/tmp/mysql.pid

The exact location depends on your MySQL installation method (Homebrew, official package, etc.) and configuration.

First, verify if MySQL is actually running:

ps aux | grep mysqld

If you see a mysqld process running but still get the PID file error, we need to investigate further.

MySQL's configuration file (usually my.cnf or my.ini) specifies the PID file location. Check your configuration:

mysql --help | grep my.cnf
cat /etc/my.cnf
cat /usr/local/etc/my.cnf

Look for a line like:

pid-file = /path/to/mysql.pid

Even if the PID file path is correct, permission problems can prevent MySQL from creating/writing the file. Check directory permissions:

ls -ld /usr/local/var/mysql
ls -ld /var/run/mysqld
ls -ld /tmp

The MySQL user (usually _mysql on macOS) needs write permissions to these directories.

As a temporary workaround, you can manually create the PID file:

# Find the MySQL process ID
MYSQL_PID=$(ps aux | grep mysqld | grep -v grep | awk '{print $2}')

# Create the PID file
echo $MYSQL_PID | sudo tee /usr/local/var/mysql/$(hostname).pid

# Set proper permissions
sudo chown _mysql:_mysql /usr/local/var/mysql/$(hostname).pid

Sometimes the cleanest solution is to completely stop and restart MySQL:

# Force stop any running MySQL processes
sudo pkill mysqld

# Remove any existing PID file
sudo rm -f /usr/local/var/mysql/*.pid

# Start MySQL properly
sudo /usr/local/mysql/support-files/mysql.server start

As mentioned in the original question, socket file problems can sometimes manifest as PID file issues. Verify your socket file:

ls -l /tmp/mysql.sock
ls -l /var/mysql/mysql.sock

If needed, recreate the symlink:

sudo rm -f /var/mysql/mysql.sock
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
sudo chown -R _mysql:_mysql /var/mysql

After applying these fixes, verify everything is working:

mysqladmin ping
mysqladmin status
/usr/local/mysql/support-files/mysql.server status

When working with MySQL on macOS, you might encounter the frustrating situation where the server appears to start successfully, but subsequent operations fail with the error:

ERROR! MySQL server PID file could not be found!

This typically happens when the MySQL daemon can't create or access its Process ID (PID) file, which is crucial for managing the server process.

MySQL typically looks for its PID file in these locations:

/usr/local/var/mysql/hostname.pid
/var/run/mysqld/mysqld.pid
/tmp/mysql.pid

On modern macOS installations with Homebrew, you'll often find it at:

/usr/local/var/mysql/hostname.pid

First, verify if MySQL is actually running:

ps aux | grep mysqld

If it's running but you're getting the PID error, check these common causes:

  • Incorrect permissions on the PID file directory
  • MySQL configuration pointing to wrong PID file location
  • Filesystem issues preventing file creation

Edit your MySQL configuration file (typically my.cnf or my.ini) and explicitly set the PID file location:

[mysqld]
pid-file = /usr/local/var/mysql/mysql.pid

Then create the directory if it doesn't exist and set proper permissions:

sudo mkdir -p /usr/local/var/mysql
sudo chown -R _mysql:_mysql /usr/local/var/mysql
sudo chmod -R 755 /usr/local/var/mysql

If MySQL creates the PID file in an unexpected location, you can create a symbolic link:

sudo ln -s /actual/path/to/mysql.pid /expected/path/mysql.pid

For example:

sudo ln -s /tmp/mysql.pid /usr/local/var/mysql/mysql.pid

After making changes, restart MySQL and verify:

sudo /usr/local/mysql/support-files/mysql.server restart
ls -la /usr/local/var/mysql/ | grep pid

You should see the PID file created with proper permissions.

If the issue persists, try these steps:

# Check MySQL error logs
tail -n 50 /usr/local/var/mysql/*.err

# Verify directory ownership
ls -ld /usr/local/var/mysql/

# Test creating a file manually
sudo -u _mysql touch /usr/local/var/mysql/test.pid

Remember that on macOS, MySQL typically runs under the _mysql user, so all files need to be accessible by this user.