Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

MySQL start fails with: the server quit without updating the PID file

ErrorCan't start server: Bind on TCP/IP port: Address already in use

Short answer

This message is only a symptom: mysqld started and exited before it wrote its PID file. The reason is in the MySQL error log in the data directory. The documented causes are a port or socket already in use, a wrong data directory path, and file permissions on the data directory. Read the log first, then fix the one it names.

  • Applies to MySQL 8.4 LTS, Homebrew on macOS, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the error log. It is the host_name.err file in the data directory. For Homebrew the data directory is under the Homebrew prefix, for example /opt/homebrew/var/mysql.

    ls /opt/homebrew/var/mysql/*.err
    tail -n 50 /opt/homebrew/var/mysql/*.err
  2. 2Match what you see, then jump to its fix

    1. 1Can't start server: Bind on TCP/IP port: Address already in use (or Bind on unix socket)Another mysqld, or another program, holds the port or socketFix
    2. 2Errcode: 13 (Permission denied), or a message that the data directory or the mysql grant tables cannot be found.The data directory is missing, wrong, or not readableFix
    3. 3Permission denied in the log although file ownership looks correct.Security software blocks mysqld from its directoriesFix

What does the error look like?

  • Can't start server: Bind on TCP/IP port: Address already in use

Cause 1 of 3

Another mysqld, or another program, holds the port or socket

1Check

Look for a second mysqld, and for any process on port 3306. A server started by hand, by an installer and by a service manager at the same time is the usual way this happens.

ps aux | grep [m]ysqld
lsof -nP -iTCP:3306 -sTCP:LISTEN

2Fix

Stop the other server first. With Homebrew, stop the service by name. If a different program owns the port, stop it or start MySQL on another port with the port option.

brew services list
brew services stop mysql
brew services start mysql

3Verify

The service shows started, and a client connects.

brew services info mysql
mysqladmin -u root -p status

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 3

The data directory is missing, wrong, or not readable

1Check

Print the data directory the server is really using, and check who owns it. The account that runs mysqld must own it.

mysqld --verbose --help | grep -E "^(datadir|basedir)"
ls -la /opt/homebrew/var/mysql | head

2Fix

Point datadir or basedir at the right place, and give ownership of the directory to the account that runs the server. On a fresh install where initialization never ran, the manual says to remove the data directory and initialise again with --user. That deletes every database in it, so do it only on an empty install.

sudo chown -R mysql:mysql /var/lib/mysql
# empty install only: re-initialise
mysqld --initialize --user=mysql

3Verify

Start the server and check that the error log has no new errors.

tail -n 20 /var/lib/mysql/*.err

Confirmed by dev.mysql.com

Did this fix it?

Cause 3 of 3

Security software blocks mysqld from its directories

1Check

Mandatory access control and similar security tools can block access even when ownership is right. Check whether such a tool logged a denial.

sudo dmesg | tail -n 30

2Fix

Reconfigure the security software so mysqld may use its data directory. Do not run the server as root as a workaround.

# Add an allow rule for mysqld and its data directory in your security tool.

3Verify

Start the server again and read the error log.

tail -n 20 /var/lib/mysql/*.err

Confirmed by dev.mysql.com

Did this fix it?

How do I stop it coming back?

  • Start MySQL in one way only: either brew services, or a manual launch, never both.
  • Keep the data directory outside paths a cleanup tool or sync client touches.
  • Take a backup before upgrading the formula, since an upgrade can leave an incompatible data directory.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.