localhost:3306
Port 3306 is MySQL territory. Every MySQL server listens here by default. Unlike web ports, you don't open this in a browser — you connect with a MySQL client, phpMyAdmin, or your application's database driver.
Connect to MySQL
Command Line
# Local connection
mysql -u root -p
# Specify host and port
mysql -h localhost -P 3306 -u root -p
# Connect to remote server
mysql -h 192.168.1.100 -P 3306 -u myuser -p
Connection String
# PHP (PDO)
$pdo = new PDO('mysql:host=localhost;port=3306;dbname=mydb', 'user', 'pass');
# Node.js
mysql.createConnection({
host: 'localhost',
port: 3306,
user: 'root',
password: 'password',
database: 'mydb'
});
# Python
connection = mysql.connector.connect(
host='localhost',
port=3306,
user='root',
password='password'
)
Check if MySQL is Running
# Linux
sudo systemctl status mysql
# Mac (Homebrew)
brew services list | grep mysql
# Check port
netstat -an | grep 3306
Can't Connect?
| Error | Solution |
|---|---|
| Connection refused | MySQL not running. Start the service. |
| Access denied | Wrong username/password or missing privileges |
| Host not allowed | User needs GRANT for your host |
| Socket error | Try 127.0.0.1 instead of localhost |
Change MySQL Port
# my.cnf or my.ini
[mysqld]
port = 3307
# Then restart MySQL
MySQL vs MariaDB
MariaDB (MySQL fork) also uses port 3306 by default. They're compatible — same port, same protocol.
Related Ports
| Port | Database |
|---|---|
| 5432 | PostgreSQL |
| 27017 | MongoDB |
| 6379 | Redis |
| 1433 | SQL Server |