Port 3306

MySQL / MariaDB Database

Port 3306: MySQL Database

Protocol TCP
Service MySQL / MariaDB
Encrypted Optional (SSL/TLS)
IANA Status Official

What is Port 3306?

Port 3306 is the default port for MySQL and MariaDB database servers. Clients connect to this port to execute SQL queries and manage databases.

Connection Examples

# MySQL command line
mysql -h hostname -P 3306 -u username -p

# Connection string
mysql://user:password@localhost:3306/database

# Node.js
const connection = mysql.createConnection({
  host: 'localhost',
  port: 3306,
  user: 'root',
  password: 'secret',
  database: 'myapp'
});

# Python
connection = mysql.connector.connect(
    host="localhost",
    port=3306,
    user="root",
    password="secret"
)

Security Best Practices

Never expose MySQL to the internet

Keep port 3306 firewalled. Connect via SSH tunnel or private network.

# /etc/mysql/mysql.conf.d/mysqld.cnf

# Bind to localhost only (recommended)
bind-address = 127.0.0.1

# Or specific private IP
bind-address = 10.0.0.5

# Restart MySQL
sudo systemctl restart mysql

SSH Tunnel for Remote Access

# Create SSH tunnel
ssh -L 3307:localhost:3306 user@server

# Connect via tunnel (uses local port 3307)
mysql -h 127.0.0.1 -P 3307 -u dbuser -p

# Keep tunnel open in background
ssh -fN -L 3307:localhost:3306 user@server

Troubleshooting

# Check if MySQL is running
systemctl status mysql
sudo ss -tlnp | grep 3306

# Check bind address
mysql -u root -p -e "SHOW VARIABLES LIKE 'bind_address';"

# Test connection
nc -zv localhost 3306
mysql -h hostname -P 3306 -u user -p

# Check MySQL logs
sudo tail -f /var/log/mysql/error.log

Common Issues

  • Access denied: Check username, password, and host permissions
  • Connection refused: MySQL not running or bound to wrong interface
  • Too many connections: Increase max_connections or close leaked connections
  • Host blocked: Too many connection errors, flush hosts

Grant Remote Access

# Only if you need remote access (not recommended)
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database.* TO 'username'@'%';
FLUSH PRIVILEGES;

# Better: limit to specific IP
CREATE USER 'username'@'10.0.0.5' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database.* TO 'username'@'10.0.0.5';
FLUSH PRIVILEGES;

Monitor your database health

UptimeSignal can monitor TCP port 3306 to ensure your MySQL server is accessible.

Start monitoring free →

Related Ports