Setting Up SSH Tunnels

Introduction

SSH tunnels allow you to securely connect to MySQL databases that are behind firewalls or only accessible via SSH.

When to Use SSH Tunnels

  • Database behind firewall
  • Remote server access
  • Security requirements
  • No direct MySQL port access

Setting Up SSH Tunnel

Step 1: Enable SSH Tunnel

  1. Open connection dialog
  2. Check "Use SSH Tunnel"
  3. SSH configuration appears

Step 2: Configure SSH

Enter SSH details:

  • SSH Host: SSH server address
  • SSH Port: Usually 22
  • SSH Username: Your SSH username
  • Authentication: Password or private key

Step 3: Configure MySQL

Enter MySQL details:

  • MySQL Host: Usually localhost (through tunnel)
  • MySQL Port: Usually 3306
  • Username: MySQL username
  • Password: MySQL password

Step 4: Test Connection

  1. Click "Test Connection"
  2. SSH tunnel establishes
  3. MySQL connects through tunnel
  4. Save connection

Authentication Methods

Password Authentication

  1. Select "Password"
  2. Enter SSH password
  3. Stored encrypted
  4. Simple setup

Private Key Authentication

  1. Select "Private Key"
  2. Browse to key file
  3. More secure
  4. No password needed

Troubleshooting

SSH Connection Fails

  • Verify SSH host and port
  • Check SSH credentials
  • Test SSH connection separately
  • Review firewall rules

MySQL Connection Fails

  • Verify MySQL host (usually localhost)
  • Check MySQL credentials
  • Ensure MySQL is running
  • Review MySQL user permissions

Best Practices

Security

  • Use private keys when possible
  • Limit SSH access
  • Use strong passwords
  • Regular key rotation

Performance

  • Keep tunnels active
  • Monitor connection health
  • Use connection pooling
  • Optimize network

Next Steps