Port 3306: what it is
Port 3306 is the default TCP port of MySQL and MariaDB. Applications connect to it with a connection string such as mysql://user:pass@host:3306/db. Unlike the web ports, a database port should rarely be open to the whole internet: it is meant to be reachable by your application servers only.
In the port lookup it is listed as MySQL, MariaDB on TCP. This page opens that tool on 3306.
- The X Protocol of MySQL 8 uses its own port, 33060; 3306 is the classic protocol every driver speaks.
- MariaDB uses the same port, so a client written for one connects to the other.
- By default the server only listens on localhost on many packages (bind-address = 127.0.0.1); a remote client needs that changed on purpose.
Test it and open it
Test the port and connect
nc -vz db.example.com 3306
mysql -h db.example.com -P 3306 -u app -p
sudo ss -ltnp | grep 3306 # on the serverListen on the private address of the server
# /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
port = 3306
bind-address = 10.0.0.5Errors you will meet
| Message | What it usually means |
|---|---|
ERROR 2003 (HY000): Can't connect to MySQL server | No connection: the server is down, bind-address keeps it on localhost, or a firewall blocks 3306. |
ERROR 1045 (28000): Access denied for user | The port is reachable, but the user or password is wrong, or that user is not allowed from your host. |
ERROR 1130: Host is not allowed to connect | The server saw your connection but has no account for your IP: create the user for that host and run GRANT. |
Keep it safe
- Never expose 3306 to 0.0.0.0/0. Allow only the IPs of your application servers in the firewall or the security group.
- For maintenance from your computer use an SSH tunnel instead of opening the port: ssh -L 3306:127.0.0.1:3306 user@server.
- Create one MySQL user per application with GRANT on its own schema and a host pattern, never root from outside.
Neighbours in the same category
Other database ports in the lookup tool:
| Port | Protocol | Service | Source |
|---|---|---|---|
| 3306 | TCP | MySQL, MariaDB | IANA registry |
| 1433 | TCP | SQL Server | IANA registry |
| 1434 | UDP | SQL Server Browser | IANA registry |
| 1521 | TCP | Oracle Database | Usual default of the product |
| 5432 | TCP | PostgreSQL | IANA registry |
| 5984 | TCP | CouchDB | IANA registry |
| 6379 | TCP | Redis | Usual default of the product |
| 8086 | TCP | InfluxDB | Usual default of the product |
Look up another port
- Type a port number (443), a range (8000-8100) or a word (database) in the search box.
- Filter by protocol (TCP or UDP) or by category with the buttons above the table.
- Copy a line, or print the table as a one-page reference.
Frequently asked questions
Is port 3306 safe to leave open?
Not to the internet. Bots scan 3306 all day and try common passwords. Restrict it to known IPs, or keep it closed and use an SSH tunnel.
How do I change the MySQL port?
Set port = 3307 (or another) in the [mysqld] section, restart the service and give clients the new port with -P 3307 or in the connection string.
What is the default port of PostgreSQL?
- MySQL is 3306, MongoDB 27017 and Redis 6379; the lookup tool lists them with their category.