What Port 3306 Is
Port 3306 is the default TCP port of MySQL and MariaDB. Applications on other machines connect to it to run queries, and so does the mysql client when it connects over the network. Programs on the same server usually connect through a local Unix socket file instead and do not use the port at all. MySQL 8 and later also listen on port 33060 for the X Protocol used by MySQL Shell; treat that port the same way as 3306. If you are new to the database itself, see what is MySQL.
See What Listens on Port 3306
sudo ss -ltnp 'sport = :3306'The process column shows mysqld or mariadbd. The local address tells you who can connect:
- 127.0.0.1:3306: only programs on the server itself. This is the safe state for a database used by a local application.
- 0.0.0.0:3306, [::]:3306, or *:3306: every network interface. Whether outsiders reach it now depends only on the firewall.
The bind-address Setting
The bind-address option decides which address the server listens on. Where it usually lives:
- MySQL from Ubuntu's packages: /etc/mysql/mysql.conf.d/mysqld.cnf, set to 127.0.0.1 by default, with a matching line for port 33060.
- MariaDB on Ubuntu and Debian: /etc/mysql/mariadb.conf.d/50-server.cnf, also 127.0.0.1 by default.
- AlmaLinux and Rocky Linux: /etc/my.cnf.d/mariadb-server.cnf or mysql-server.cnf, with no active bind-address line, so the server listens on all addresses and only the firewall keeps it private.
Find every place it is set:
sudo grep -rn bind-address /etc/mysql/ /etc/my.cnf /etc/my.cnf.d/ 2>/dev/nullKeep 127.0.0.1 unless another server must connect directly.
Why Port 3306 Should Not Face the Internet
Bots scan the whole internet for open database ports and try common user names and passwords around the clock. An open port also exposes any flaw in the database server to every attacker before a password is even needed, and database traffic without TLS can be read on the way. Never open port 3306 to everyone. The two safe forms are an SSH tunnel and a firewall rule for one source address.
Use an SSH Tunnel Instead
For an administrator or a database tool on your own computer, a tunnel needs no open database port. On your computer:
ssh -N -L 3307:127.0.0.1:3306 user@your_server_ipWhile it runs, connections to port 3307 on your computer arrive at the database as local connections on the server:
mysql -h 127.0.0.1 -P 3307 -u app_user -pThe database keeps listening on 127.0.0.1 only. Other forms are in SSH tunneling.
Allow One Source Address
When an application server must connect directly, open the port for that one address. If you work over SSH, make sure SSH is allowed and keep your session open before you touch the firewall. Set bind-address to this server's own address that the other server will connect to, restart the database (sudo systemctl restart mysql or sudo systemctl restart mariadb), and add one rule. With UFW:
sudo ufw allow from 203.0.113.10 to any port 3306 proto tcpWith firewalld:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.10" port port="3306" protocol="tcp" accept'
sudo firewall-cmd --reloadThe database account must be limited to that host as well, not allowed from every host. The account and TLS steps are in MySQL remote access. If both servers share a private network, use its addresses so the traffic never crosses the internet.
Test the Port from Outside
From the allowed host, and from one that should be refused, against servers you administer:
nc -zv your_server_ip 3306The allowed host should connect; any other should time out. If the port opens from everywhere, look for a container: a database started by Docker with -p 3306:3306 is published through Docker's own rules, past UFW and firewalld. Bind it to 127.0.0.1 instead, as shown in Docker port mapping.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations