TCP · Port 3306IANA Registered

Port 3306 — MySQL / MariaDB

Default TCP listening port for MySQL and MariaDB relational database server connections.

⚡ Primary Use Cases & Environments

  • ✓Web applications (WordPress, Laravel, Node.js) connecting to MySQL
  • ✓Database administration via phpMyAdmin or TablePlus

🛡️ Security & Vulnerability Analysis

Never bind MySQL to 0.0.0.0 on an internet-facing server. Set "bind-address = 127.0.0.1" in my.cnf unless remote connections are strictly firewalled.

🔧 Network Diagnostics & Inspection

1. Check Active Listening Sockets (Local Host)
Terminal Command
$ sudo ss -tuln | grep :3306
Inspects whether any local process daemon is bound to port 3306.
2. Remote Port & Service Scan (Nmap)
Terminal Command
$ nmap -p 3306 -sV --script mysql-info <target-ip>
Probes target IP to determine whether port 3306 is open, closed, or filtered.
3. Wireshark Capture / Display Filter
mysql or tcp.port == 3306Wireshark Filter

🔥 Firewall Configuration Rules (UFW & iptables)

UFW (Uncomplicated Firewall)
Terminal Command
$ sudo ufw allow from <app-server-ip> to any port 3306 proto tcp
Applies a persistent Linux UFW firewall rule for port 3306.
iptables Command
Terminal Command
$ sudo iptables -A INPUT -p tcp -s <app-server-ip> --dport 3306 -j ACCEPT
Appends a direct netfilter kernel rule to the INPUT chain for port 3306.

❓ Frequently Asked Questions (FAQ)

How do I check if MySQL is listening locally or publicly?

Run "sudo ss -tuln | grep 3306". If it displays "127.0.0.1:3306", it is safely restricted to local connections. If it displays "0.0.0.0:3306", it is exposed to the network.

How do I safely connect to a remote MySQL server?

Use an SSH tunnel: "ssh -L 3307:127.0.0.1:3306 user@remote-host". Then connect your database GUI locally to 127.0.0.1:3307.

Related Networking Tools & Guides