Port 3306 (MySQL)

Port 3306: MySQL and MariaDB, tests, bind-address, SSH tunnel and common errors.

loading Port 3306 (MySQL)
About this tool

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 server

Listen on the private address of the server

# /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
port = 3306
bind-address = 10.0.0.5

Errors you will meet

MessageWhat it usually means
ERROR 2003 (HY000): Can't connect to MySQL serverNo connection: the server is down, bind-address keeps it on localhost, or a firewall blocks 3306.
ERROR 1045 (28000): Access denied for userThe 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 connectThe 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:

PortProtocolServiceSource
3306TCPMySQL, MariaDBIANA registry
1433TCPSQL ServerIANA registry
1434UDPSQL Server BrowserIANA registry
1521TCPOracle DatabaseUsual default of the product
5432TCPPostgreSQLIANA registry
5984TCPCouchDBIANA registry
6379TCPRedisUsual default of the product
8086TCPInfluxDBUsual default of the product

Look up another port

  1. Type a port number (443), a range (8000-8100) or a word (database) in the search box.
  2. Filter by protocol (TCP or UDP) or by category with the buttons above the table.
  3. 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?

  1. MySQL is 3306, MongoDB 27017 and Redis 6379; the lookup tool lists them with their category.
Report a problem