Connecting to MySQL via SSH Tunnel (Firstserv Guide)
Connecting directly to MySQL over port 3306 is not encrypted, which can pose a security risk. To ensure your database connection is secure, Firstserv recommends using an SSH tunnel.
What is an SSH Tunnel?
An SSH tunnel securely routes your database connection through your hosting account using encryption.
✅ Benefits
- Encrypts all database traffic
- Protects login credentials
- Avoids exposing your database to the public internet
How It Works
- You create a secure SSH connection to your server
- This connection forwards your local port to the MySQL server
- You connect locally (e.g. localhost), but traffic is securely routed to your hosting account
Connection Overview
| Type | Value |
|---|---|
| SSH Port | 722 |
| MySQL Port | 3306 |
| MySQL Host (local) | localhost or 127.0.0.1 |
Requirements
Before you begin:
- ✅ SSH access enabled on your Firstserv account
- ✅ Your cPanel username and password
- ✅ Your database username and password
Mac / Linux Setup (Terminal)
Step 1: Open Terminal
Use Spotlight or Applications → Utilities → Terminal
Step 2: Create the Tunnel
Run the following command:
Replace Values
- username → your cPanel username
- yourdomain.com → your domain or server hostname
Example
Step 3: Enter Password
- Enter your cPanel password when prompted
- The terminal will remain open (this is normal)
✅ Your tunnel is now active
Optional: Run in Background
To run the tunnel in the background:
⚠️ Port Conflict Note
If you already have MySQL running locally:
👉 Then connect using:
localhost:3333
Windows Setup (PuTTY)
Step 1: Open PuTTY
- Enter your:
- Host Name (domain or server hostname)
- Port: 722
Step 2: Configure Tunnel
- Go to:
Connection → SSH → Tunnels
- Enter:
- Source Port: 3306
- Destination: localhost:3306
- Click Add
Step 3: Save (Optional)
- Go back to Session
- Enter a name under Saved Sessions
- Click Save
Step 4: Connect
- Click Open
- Enter your cPanel password
✅ Keep the window open to maintain the tunnel
Connecting to MySQL
Once the tunnel is active, connect using your database tool (e.g. MySQL Workbench):
Host: localhost (or 127.0.0.1) Port: 3306 (or your custom port) Username: your MySQL user Password: your MySQL password
✅ All traffic is now securely routed via SSH
Summary
- Direct MySQL connections are not secure
- SSH tunnels encrypt your database traffic
- Use:
SSH Port: 722 MySQL Port: 3306
- Connect locally while securely accessing your remote database
Need Help?
If you need help setting up an SSH tunnel or connecting your database securely, the Firstserv support team is always happy to assist.
