MySQL start fails with: the server quit without updating the PID file
Can't start server: Bind on TCP/IP port: Address already in useShort 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.
Fix it fast
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/*.err2Match what you see, then jump to its fix
- 1
Can'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
Errcode: 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
Permission denied in the log although file ownership looks correct.Security software blocks mysqld from its directoriesFix
- 1
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:LISTEN2Fix
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 mysql3Verify
The service shows started, and a client connects.
brew services info mysql
mysqladmin -u root -p statusConfirmed by dev.mysql.com
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 | head2Fix
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=mysql3Verify
Start the server and check that the error log has no new errors.
tail -n 20 /var/lib/mysql/*.errConfirmed by dev.mysql.com
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 302Fix
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/*.errConfirmed by dev.mysql.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
The client cannot reach the MySQL or MariaDB server through its Unix socket file
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2) (MariaDB client wording)
Error 2002 means the client tried the Unix socket file named in the message and found nothing it could talk to.
4 causes, each with a fixDatabases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
An EC2 instance cannot reach its RDS database
Could not open connection to the host, on port <port>: Connect failed
RDS denies all access until a security group allows it.
3 causes, each with a fixDatabases
Locked out of a fresh MariaDB install as root on Mac or Linux
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
A fresh MariaDB root account is not a normal password account.
3 causes, each with a fixDatabases
An Aria table fails with 'Read page with wrong checksum' (error 1030, code 176)
ERROR 1030 (HY000): Got error 176 "Read page with wrong checksum" from storage engine Aria
Code 176 means MariaDB's Aria engine read a data or index page whose checksum does not match, so that table file is damaged.
3 causes, each with a fix