PortScan › Port guide › Port 3306

Port 3306 (MySQL): Why Allowing Remote Access Is Risky and How to Secure It

TCP 3306MySQL / MariaDBDatabaseExposure risk: High

Port 3306 is the MySQL/MariaDB default. Open to the internet, it invites password guessing, data theft and ransom. bind-address, host-limited accounts, SSH tunnels.

What is port 3306?

Port 3306 is the default port for MySQL and MariaDB. A large number of web services, WordPress among them, run on this database.

If the web server and the database are on the same machine, the database only needs to listen on 127.0.0.1. The most common reason for allowing remote access is "so I can connect with a DB tool from home" — and even then there is no need to open the port (see the SSH tunnel below).

When it is normally open

Risks if it is open

Credential guessing

If the root account is allowed to connect remotely ('root'@'%') and the password is weak, it falls within hours.

Database hostage-taking

Attacks that break into an exposed MySQL, delete the data and leave behind only a table saying "send bitcoin and we'll give it back" have happened again and again. In many cases the data was never actually kept, so paying gets you nothing back.

Security checklist

How to check whether port 3306 is open

From outside (is it exposed to the internet?)

Whether your server or home router accepts port 3306 from the internet can only be confirmed by connecting from outside. A check from inside the same network bypasses the router's firewall and gives a different answer.

PortScan opens a real TCP connection from the Cloudflare edge and reports Open, Closed or Filtered. Members can scan every port on their own IP for free and other targets free once a day.

Check port 3306

On the server (what is listening?)

Windows (PowerShell):

netstat -ano | findstr ":3306 "
Get-NetTCPConnection -LocalPort 3306 -State Listen | Select LocalAddress,OwningProcess

Linux:

sudo ss -tlnp | grep ':3306 '

If it listens on 0.0.0.0 or [::] it is open on every network; 127.0.0.1 means only that machine can connect. To test port 3306 on a server from another computer, use Test-NetConnection server-address -Port 3306 on Windows or nc -vz server-address 3306 on Linux and macOS.

How to close or restrict port 3306

The best fix is to turn the service off or make it listen only on 127.0.0.1 (see the checklist above). If you need the service but must keep it off the internet, use a firewall.

Windows Firewall

# Administrator PowerShell
New-NetFirewallRule -DisplayName "Block TCP 3306" -Direction Inbound -Protocol TCP -LocalPort 3306 -Action Block
# To allow a single IP instead (block rules take precedence, so use this instead of the rule above)
New-NetFirewallRule -DisplayName "Allow TCP 3306 from office" -Direction Inbound -Protocol TCP -LocalPort 3306 -RemoteAddress 203.0.113.10 -Action Allow

Linux (ufw)

sudo ufw deny 3306/tcp
# Allow a single IP only
sudo ufw allow from 203.0.113.10 to any port 3306 proto tcp

On a cloud server, also check port 3306 in the security group (inbound rules), which is separate from the OS firewall. For services running in Docker, the rules Docker creates can bypass ufw, so binding the port to localhost with -p 127.0.0.1:3306:3306 is the reliable option.

Router

At home or in a small office, open the router's admin page and check whether port 3306 is in the port forwarding list, whether DMZ is enabled, and whether any program opened ports by itself through UPnP. If any of the three applies, port 3306 on your PC is directly visible from the internet.

How to read the scan result

The verdict can depend on where you connect from. Many ISPs (including most Korean ISPs) block some ports such as 135, 139 and 445 on their network, so the same server can look Filtered from inside that network and Closed from abroad.

FAQ

Does the same apply to cloud databases (RDS, etc.)?
Yes. The baseline is to turn off the "public access" option and allow only application servers in the security group.
5432 PostgreSQL1433 MS SQL Server6379 Redis33060 MySQL X

Last updated 2026-11-04 · Use this guide to check systems you manage. Scanning systems without permission may carry legal liability.