Guide

Port 3306 already in use on Mac? Fix MySQL

MySQL says it can’t bind port 3306, or Docker can’t publish it. On a Mac that almost always means a second MySQL or MariaDB is already running, often one installed months ago that starts with the Mac. Find which one, then stop it with the tool that started it.

By Anmol Sethi · Updated

In short

Run sudo lsof -nP -iTCP:3306 -sTCP:LISTEN to see what holds the port, then ps -o user=,command= -p <PID> to see where it came from. Stop Homebrew’s with brew services stop mysql (or mysql@8.4, mariadb), a container with docker stop, and the official installer’s in System Settings → MySQL. Killing mysqld alone doesn’t last: its service manager starts it again.

Ask AIChatGPTClaudePerplexityGoogle AIGrok

The errors

[ERROR] [MY-010262] [Server] Can't start server: Bind on TCP/IP port: Address already in use
[ERROR] [MY-010257] [Server] Do you already have another mysqld server running on port: 3306 ?

From Docker it reads Bind for 0.0.0.0:3306 failed: port is already allocated. Same cause, seen from the other side.

Find what holds 3306

sudo lsof -nP -iTCP:3306 -sTCP:LISTEN
COMMAND  PID  USER   FD   TYPE  NODE NAME
mysqld  1895   you   31u  IPv4  TCP 127.0.0.1:3306 (LISTEN)

Use sudo: the official installer runs MySQL as the _mysql user, and without sudo its listener stays hidden. Then see where it came from:

ps -o user=,command= -p 1895
The command containsIt’sStop it with
/opt/homebrew/ or /usr/local/ (Cellar, opt/mysql)Homebrewbrew services stop mysql@8.4 (the name from brew services list)
/usr/local/mysql and user _mysqlThe installer from mysql.comSystem Settings → MySQL → Stop
com.docker, vpnkit or OrbStackA Docker containerdocker stop <container>
DBngin, MAMP or XAMPPThat appStop it in the app

MySQL also listens on 33060 for its X Protocol. If a second server complains about 33060, it’s the same conflict.

Homebrew

brew services list
brew services stop mysql@8.4

Homebrew’s service restarts MySQL whenever it exits, which is why kill or mysqladmin shutdown doesn’t seem to work. brew services stop also keeps it from starting at login. Have both mysql and mariadb installed? Only one can have 3306. More in Homebrew services on Mac.

The installer from mysql.com

It adds a MySQL pane at the bottom of System Settings, with Stop and an option to start MySQL when the Mac starts. Turn that off if you only want it now and then. From Terminal, find its service file and stop it:

ls /Library/LaunchDaemons | grep -i mysql
sudo launchctl bootout system /Library/LaunchDaemons/<that-file>.plist

Docker

docker ps --filter publish=3306
docker stop <container>

Or keep the local MySQL and publish the container on another port: -p 3307:3306. See the Docker port guide.

Keep both: run the second on 3307

  • Docker: -p 3307:3306.
  • Homebrew: add port = 3307 under [mysqld] in /opt/homebrew/etc/my.cnf, then brew services restart mysql@8.4.
  • Started by hand: mysqld --port=3307 --mysqlx-port=33070.

Then connect with mysql -h 127.0.0.1 -P 3307. Use 127.0.0.1, not localhost: the mysql client treats localhost as “use the socket file” and ignores the port, so it reaches the first server.

The one-click way: Portlivo

Portlivo shows MySQL and MariaDB from Homebrew, DBngin or a Docker container as one named row in the menu bar, with 3306 and 33060 together. Stop runs brew services stop or docker stop, so it stays stopped instead of coming straight back.

Servers running as another user, like the mysql.com installer’s, aren’t listed, since macOS doesn’t show them without sudo. Use System Settings for that one.

Questions people ask

I killed mysqld and it came back. Why?
Its service manager restarted it: Homebrew’s launchd agent, the installer’s system service, or Docker. Stop it through that tool, such as brew services stop mysql.
Why does mysql -P 3307 still connect to the 3306 server?
With -h localhost the client uses the socket file and ignores the port. Connect with -h 127.0.0.1 -P 3307.
What is port 33060?
MySQL’s X Protocol, used by MySQL Shell and the document store. A normal mysqld opens it next to 3306.

Try Portlivo free for 7 days. Every feature, no account.Then $8.99 once, no subscription.

Download for Mac

Still have a question?

Write to us — a real developer reads every email and replies personally.

support@portlivo.com