What’s running on port 3306 on my Mac?
3306 is MySQL’s port, and MariaDB’s too. The usual questions are which install owns it (you may have two) and whether it’s listening on more than localhost.
Updated
Commonly used by
- MySQLThe server (
mysqld) listens on 3306; the X Protocol uses 33060. - MariaDBDrop-in replacement, same default port, same
mysqld/mariadbdprocess. - DBngin / MAMP / Laravel HerdLocal database managers that run their own MySQL on 3306.
- Docker
mysqlimagePublished with-p 3306:3306, it shows up ascom.docker.backend.
Check what’s on port 3306
lsof -nP -iTCP:3306 -sTCP:LISTEN
mysqld or mariadbd is a native install. Find out which one from its path:
ps -o pid,command -p <PID>
A path under /opt/homebrew is Homebrew (brew services list shows it). Paths inside /Applications/DBngin.app or /Applications/MAMP point to those apps. com.docker.backend or OrbStack means a container; docker ps --filter publish=3306 names it.
With Stat Space: statspace port 3306.
Free it or move it
| Install | Stop it | Change the port |
|---|---|---|
| Homebrew | brew services stop mysql | port = 3307 under [mysqld] in /opt/homebrew/etc/my.cnf |
| Docker | docker stop <name> | -p 127.0.0.1:3307:3306 |
| DBngin / MAMP | Stop from the app | Port field in the app’s settings |
Two MySQL servers on one Mac is common after trying several tools. They don’t share data, so a “missing database” is often just the wrong server.
Security: never expose 3306
A database on 0.0.0.0 is a much bigger risk than a dev web server. Anyone on the same Wi-Fi can try passwords against it, and a local root account with an empty or weak password is the norm in development.
- Homebrew’s
my.cnfships withbind-address = 127.0.0.1. Keep it. - Docker’s
-p 3306:3306listens on every interface. Write-p 127.0.0.1:3306:3306instead, or in Compose:"127.0.0.1:3306:3306". - Check with
lsof: you want127.0.0.1:3306, never*:3306.
More in dev server exposed to the network.
Seeing it live
Stat Space shows 3306 with the install behind it and flags it if it’s bound to all interfaces. With Pro, a Docker-published MySQL shows the container name and image instead of com.docker.backend.
Questions
Why does MySQL say port 3306 is already in use?
Another MySQL is already running: a Homebrew service, DBngin, MAMP or a Docker container. Run lsof -nP -iTCP:3306 -sTCP:LISTEN, then stop the one you don't want with brew services stop mysql or docker stop <name>.
How do I change MySQL's port on a Mac?
Add port = 3307 under [mysqld] in /opt/homebrew/etc/my.cnf and restart with brew services restart mysql. Clients then connect with mysql -h 127.0.0.1 -P 3307.
Why does mysql -P 3307 still connect to the wrong server?
With -h localhost, the client uses the Unix socket and ignores the port. Use -h 127.0.0.1 to force TCP.
Know what your Mac is doing, without adding to it.
Free, no account. Pro is $9.99 once for the first 100 buyers.