MySQL server default ports: 3306 and 33060
MySQL server uses TCP ports 3306 and 33060 by default. mysqld cannot start while another program holds the TCP/IP port or Unix socket file it wants. The manual’s start-up troubleshooting page shows output that includes Address already in use, and says the other program may be another mysqld.
Key facts
| Port | Protocol | Role | Category |
|---|---|---|---|
| 3306 | TCP | classic MySQL protocol | Database |
| 33060 | TCP | X Protocol (mysqlx_port) | Database |
What happens when the port is busy
mysqld cannot start while another program holds the TCP/IP port or Unix socket file it wants. The manual’s start-up troubleshooting page shows output that includes Address already in use, and says the other program may be another mysqld. Stop it, or start mysqld on a different port with --port. If you run two servers on purpose, the manual requires a different Unix socket file and TCP/IP port for every mysqld.
Change the port
[mysqld]
port=3307
mysqlx_port=33061port goes under [mysqld]. mysqlx_port is a separate setting for the X Protocol port and can only be set at server startup, so change both when you run a second instance, then restart mysqld.
mysqld --port=3307--port is the command-line form. The manual tells you to use it to make mysqld listen on a different port.
mysql --host=127.0.0.1 --port=3307
# or set the default for every client in this shell
export MYSQL_TCP_PORT=3307Clients default to 3306. Command-line options override option files, and option files override environment variables.
# add the -e options your image needs before the image name
docker run -p 3307:3306 mysql:8.4The format is HOST_PORT:CONTAINER_PORT. mysqld inside the container keeps listening on 3306, so only the host side moves. Publish 33060 with a second -p if you also need the X Protocol.
Environment variable: MYSQL_TCP_PORT. Sets the default TCP/IP port number for MySQL client programs. A --port option on the command line, or a port in an option file, overrides it. Set it in the shell before you start a client.
Bind address
bind_address defaults to *, so mysqld accepts TCP/IP connections on all IPv4 interfaces and, where IPv6 is supported, all IPv6 interfaces. It is not loopback-only by default, though an installer may set its own value. A single IP address limits the server to that address, so for local work set bind_address=127.0.0.1 under [mysqld]. mysqlx_bind_address, for X Protocol, also defaults to *.
What else uses this port
No other tool in this dataset uses ports 3306 or 33060 as a default.
The dataset is the 12 tools on the ports index.
Find and free this port
These commands find the process that holds TCP port 3306 and stop it. They come from the Port in use command generator. PID_NUMBER stands for the process ID you read from the first command: replace it before you run the others.
lsof -nP -iTCP:3306 -sTCP:LISTEN
ps -p PID_NUMBER -o pid,ppid,user,command
kill -TERM PID_NUMBERss -ltnp 'sport = :3306'
ps -p PID_NUMBER -o pid,ppid,user,command
kill -TERM PID_NUMBERGet-NetTCPConnection -LocalPort 3306 -State Listen -ErrorAction SilentlyContinue | Select-Object LocalAddress, LocalPort, State, OwningProcess
Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = PID_NUMBER" | Select-Object ProcessId, ParentProcessId, Name, CommandLine
Stop-Process -Id PID_NUMBERRead the output of the second command before you stop anything, because the owner may be a container or another person’s process. Then run the first command again to confirm the port is free.
Next free ports
Counting up from 3306, the next three ports that no tool in this dataset uses as a default are 3307, 3308, and 3309. They are suggestions only: another program on your machine may hold any of them, so run the find command above before you choose one.
In Rig
Rig’s managed MySQL database is a Docker container from the mysql:8.4 image. Rig’s one-click WordPress project starts its own mysql:8.4 container on a port in the range 13306 to 13499, so it does not take 3306.
Collisions in practice
MariaDB is a different server that also lists 3306 as its default port, so a Mac with both installed, or one installed and the other in a container, has two programs competing for one number. Whichever starts second does not get it. Decide which server owns 3306, and give every other instance its own port, its own Unix socket file, and its own data directory, as the manual’s multiple-instance chapter requires. Remember mysqlx_port too: it is a separate setting, so a second instance that only changes port keeps mysqlx_port at its default of 33060, the same number the first one uses.
Frequently asked questions
What is port 33060 on a MySQL server?
It is the default port for X Plugin, MySQL’s X Protocol listener, set with the mysqlx_port system variable at server startup. It is separate from 3306, which carries the classic MySQL protocol used by the mysql client, MySQL Connectors, and mysqldump. mysqlx_bind_address defaults to * as well, so X Protocol listens on all interfaces unless you change it.
Does MariaDB use the same port as MySQL?
Yes. MariaDB’s documentation gives 3306 as the default for its port system variable, the same number as MySQL. They are separate products, and two servers cannot listen on one port at the same time, so give one of them another port with port in its option file or with --port.
How do I run a second MySQL server on the same Mac?
Each mysqld needs its own TCP/IP port, its own Unix socket file, and its own data directory. The manual describes two approaches: one option file per server, started with --defaults-file, or mysqld_multi with [mysqldN] groups in my.cnf. Give each instance its own mysqlx_port as well, because that setting defaults to 33060 and is separate from port.
Sources
- MySQL 8.4 manual: troubleshooting problems starting the MySQL server
- MySQL Port Reference: port reference tables (3306 and 33060)
- MySQL 8.4 manual: X Plugin options and system variables (mysqlx_port, mysqlx_bind_address)
- MySQL 8.0 manual: using option files ([mysqld] port)
- MySQL 8.0 manual: environment variables (MYSQL_TCP_PORT)
- MySQL 8.0 manual: server system variables (bind_address)
- MySQL 8.4 manual: running multiple MySQL instances on Unix
- MariaDB docs: server system variables (port)
- Docker docs: publishing and exposing ports
Busy ports in Rig
When a start fails because a port is taken, Rig shows which process owns it when it can, and lets you reclaim the port or choose another. You do not need Rig to use this page.