Port 3306 (MySQL): What It Is & Security Guide

May 16, 2026
Updated May 16, 2026 Port Security Guides port 3306 mysql port 3306 security what is port 3306 open port 3306 secure mysql mysql security database security tcp 3306 mysql vulnerabilities

What is Port 3306 (MySQL)?

In the vast landscape of network communication, ports act as virtual doorways, allowing different services to send and receive data. Among these, TCP port 3306 holds a particularly significant and often precarious position. It is the default port used by MySQL, one of the world's most popular open-source relational database management systems (RDBMS).

MySQL databases are the backbone of countless applications, websites, and critical business systems, storing everything from user credentials and financial transactions to product inventories and sensitive personal data. When an application needs to interact with a MySQL database, it typically initiates a connection over port 3306. This allows clients (like web servers, desktop applications, or other database tools) to query, update, and manage the data stored within the MySQL server.

Given the sensitive nature of the information typically housed within a MySQL database, the security of port 3306 is paramount. An improperly secured or exposed port 3306 can become a direct gateway for attackers to access, compromise, or even destroy your most valuable data assets. Understanding its function, inherent risks, and robust security measures is not just good practice—it's an absolute necessity for anyone managing systems that rely on MySQL.

Want to check your site right now?

Port Scanner →  ·  Website Vulnerability Scanner

Port 3306 Technical Details

To fully grasp the security implications of port 3306, it's essential to understand its technical specifications and how it operates within a network environment.

DetailValue
Port Number3306
ProtocolTCP (Transmission Control Protocol)
ServiceMySQL Database Server
Risk LevelHigh
Default StatusClosed by default on most operating systems, open if MySQL server is running and configured to listen.

The Transmission Control Protocol (TCP) is a connection-oriented protocol, meaning it establishes a reliable, ordered, and error-checked connection between two applications before data exchange begins. When a MySQL client wants to connect to a MySQL server, it initiates a three-way handshake over TCP port 3306. Once the connection is established, data (SQL queries, results, authentication credentials) flows securely and reliably between the client and the server.

While MySQL primarily uses TCP port 3306 for client-server communication, it's worth noting that other ports might be used for specific MySQL-related services, such as MySQL Router (6446), MySQL X Protocol (33060), or MySQL Shell (33060). However, 3306 remains the standard for the classic MySQL protocol.

The 'High' risk level assigned to port 3306 stems from the fact that it directly exposes a database service. Databases are often the ultimate target for attackers due to the valuable data they contain. Any vulnerability in the MySQL server software itself, or weak authentication practices, can be directly exploited if port 3306 is accessible to unauthorized parties.

Security Risks of Open Port 3306

An open and unprotected port 3306 is akin to leaving the front door of a bank vault wide open. The potential for severe damage and data loss is immense. The risks associated with an exposed MySQL port are not theoretical; they are frequently exploited in real-world cyberattacks.

Common Attacks on Port 3306

Attackers employ various sophisticated techniques to exploit exposed MySQL instances. Understanding these common attack vectors is crucial for implementing effective defensive strategies.

How to Check if Port 3306 is Open

Before you can secure port 3306, you need to know if it's currently open and accessible. There are several methods to check this, ranging from command-line tools to online scanners.

Using Nmap (Network Mapper)

Nmap is a powerful, open-source tool for network discovery and security auditing. It can quickly scan a target host to determine which ports are open.

nmap -p 3306 target.com

Replace target.com with the IP address or hostname of your server. If Nmap reports '3306/tcp open', it means the port is listening for connections. You can also scan a range of ports or use more aggressive options for detailed service detection:

nmap -p 3306 -sV target.com

The -sV option attempts to determine the service and version information running on the open port.

Using Netstat or SS (Local Check)

To check if MySQL is listening on port 3306 on the server itself (from the server's command line), you can use netstat or ss:

sudo netstat -tulnp | grep 3306

Or, for newer Linux systems:

sudo ss -tulnp | grep 3306

These commands will show if a process is listening on TCP port 3306 and which process it is (e.g., mysqld).

Using Online Port Scanners

For a quick external check without installing tools, online port scanners are invaluable. They allow you to see if your port is accessible from the internet. You can easily Scan port 3306 with our free Secably Port Scanner tool. Simply enter your server's public IP address or hostname and specify port 3306 to get an immediate assessment of its accessibility from the outside world.

Remember, if any of these checks show port 3306 as 'open' or 'listening' and you haven't explicitly configured it for external access, it's a critical security concern that needs immediate attention.

Free Security Tools

Scan your website, check open ports, find subdomains — no signup required.

See all tools →

How to Secure Port 3306

Securing port 3306 is not a one-time task but an ongoing process involving multiple layers of defense. Implementing these hardening steps is crucial for protecting your MySQL databases from unauthorized access and attacks.

When Should Port 3306 Be Open?

While the general advice is to keep port 3306 as restricted as possible, there are legitimate scenarios where it needs to be open. The key is to ensure it's open only to necessary, trusted sources and under strict security controls.

  • Internal Application Servers: The most common legitimate use case is when your web servers, application servers, or other internal services need to connect to the MySQL database. In this scenario, port 3306 should only be open to the specific internal IP addresses of these application servers, typically within the same private network or VPC.
  • Database Replication: If you have a master-slave or multi-master replication setup, the slave servers need to connect to the master server over port 3306 to synchronize data. These connections should also be restricted to the specific IP addresses of the replication partners and ideally secured with SSL/TLS.
  • Database Administration Tools: Database administrators might need to connect to the MySQL server from their workstations using tools like MySQL Workbench, DBeaver, or command-line clients. For this, it's best practice to use a VPN or a jump host to establish a secure connection to the internal network, rather than exposing port 3306 directly to the internet. If direct access is absolutely necessary (and highly discouraged), it should be limited to specific, static administrator IP addresses and protected with strong authentication and SSL.
  • Cloud-Managed Database Services: If you're using a cloud provider's managed MySQL service (e.g., AWS RDS, Google Cloud SQL, Azure Database for MySQL), the provider handles much of the underlying network security. However, you still need to configure security groups or network access controls to specify which IP addresses or other cloud resources can connect to your database instance.

In all these cases, the principle of 'least privilege' applies: only open port 3306 to the absolute minimum required IP addresses, and always secure those connections with strong authentication and encryption.

Is port 3306 dangerous?

Yes, port 3306 is considered highly dangerous if left open and unprotected to the internet. It is the default port for MySQL databases, which typically store critical and sensitive information. An exposed port 3306 provides a direct pathway for attackers to attempt unauthorized access, steal data, corrupt databases, or launch denial-of-service attacks. Its danger level is directly proportional to the value of the data it protects and the lack of security measures in place.

Should I close port 3306?

In most cases, yes, you should close port 3306 to the public internet. It should only be accessible from trusted internal networks, specific application servers, or via secure channels like a VPN. If your application server is on the same machine as the MySQL database, you should bind MySQL to the loopback address (127.0.0.1) and effectively close it to all external network interfaces. If external access is absolutely required, it must be severely restricted by firewall rules to only allow connections from known, static IP addresses and secured with SSL/TLS and strong authentication.

How do I block port 3306?

Blocking port 3306 involves configuring your server's firewall. Here are common commands for Linux systems:

Using UFW (Uncomplicated Firewall - Ubuntu/Debian)

sudo ufw deny 3306

To allow specific IP addresses (e.g., your application server's IP):

sudo ufw allow from 192.168.1.100 to any port 3306

Then, enable UFW if it's not already:

sudo ufw enable

Using iptables (CentOS/RHEL/Older Linux)

sudo iptables -A INPUT -p tcp --dport 3306 -j DROP

To allow specific IP addresses:

sudo iptables -A INPUT -p tcp -s 192.168.1.100 --dport 3306 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 3306 -j DROP

Remember to save your iptables rules so they persist after a reboot (commands vary by distribution, e.g., sudo service iptables save or sudo netfilter-persistent save).

For cloud environments, use the provided security group or network access control list (NACL) configurations to restrict inbound traffic on port 3306.

What runs on port 3306 by default?

By default, the MySQL database server runs on TCP port 3306. When you install and start a MySQL server, it is configured to listen for incoming client connections on this port. Any application or client tool that needs to interact with a MySQL database will attempt to establish a connection to the server's IP address on port 3306.

Scan for these vulnerabilities

Secably automatically detects the issues discussed in this article.

Start Free Scan