How to Connect to MySQL via SSH Tunnel in Linux

This Plone tutorial teaches you how to connect to localhost:3306 with MySQL Query Browser by building SSH tunnel in Linux.

Open terminal window to connect to MySQL server with MySQL Query Browser via SSH tunnel.

If you want to connect to server from "outside", not from Plone, you have to build SSH tunnel to connect.

  1. Build SSH tunnel by running the following command in the terminal window:
    ssh login@server -L 3306:127.0.0.1:3306 -N
    where login and server (something like login.quintagroup.com) are your SSH connection details that can be found at your quintagroup account (https://my.quintagroup.com/username)
  2. You will get response asking you to enter your SSH password (can also be found at your quintagroup account)
    login@server's password:
  3. Now when the tunnel is built stop the previous command and set it into background to be able to initiate other commands.
    • press Ctrl+Z to stop the command and you should get response:
      [1]+ Stopped        ssh login@server -L 3306:
      127.0.0.1:3306 -N
    • to set it in background, type bg and you should get response:
      [1]+ ssh login@server -L 3306:127.0.0.1:3306 -N &
  4. Connect to MySQL server as if it is running on your local system (localhost:3306) for example by running the following command in the terminal window:
    mysql -h 127.0.0.1 -p -u user database
    where user and database - are username and database name that can be found among MySQL access details at https://my.quintagroup.com/username/mysql
  5. You will be asked to provide the password for your database that can also be found among MySQL access details at https://my.quintagroup.com/username/mysql
  6. That's it! You are in.
  7. After you are finished close application you've used to access MySQL server (for command line tool mentioned in step 4 type Ctrl+D to leave).
  8. Then return to your SSH tunnel:
    • get it into foreground: press fg and you will get the response:  
      ssh login@server -L 3306:127.0.0.1:3306 -N
    • press Ctrl+C to stop it.

Connect with our experts Let's talk