InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Ssh tutorials

  • Create ssh public/private keys on command line
  • Check if an ssh key has passphrase
  • Connect to mysql server using ssh port forwarding
  • Display keys added to ssh-agent using ssh-add
  • Find authentication methods an ssh server supports
  • Generate ssh public key from private key
  • Linux - how to enable password login on ssh server
  • Linux - ssh agent forwarding when using bastion host
  • Prevent ssh session freezing due to timeout
  • Remove passphrase from ssh private key
  • Ssh port forwarding to surf a site from different location
 
  • Home
  • > Tutorials
  • > Linux/Unix Command Line
  • > SSH

How to connect to mysql server using ssh port forwarding

By admin | Last updated on Jan 27, 2016

When mysql server is hosted on a cloud environment like amazon aws/ec2 or rackspace, connecting to it using mysql GUI tools may not be possible without opening default mysql server port 3306. It is not recommended to open port 3306 on your production server for outside world for security reasons. One option for regular mysql operations is to connect to your remote cloud server using ssh and run command line utility mysql. This is not very user friendly option.

The second option is to use phpmyadmin and do admin stuff from web interface. This option is slightly better if your mysql password is strong and you use it over https. But this will require setting up secure web server setup. Also the web interface may have its own limitations as compared to a GUI client.

My favorite option is to use ssh port forwarding feature. Assuming you already have a pretty good ssh password or RSA/DSA based ssh login setup, this will not add to any additional security risk. Here are the steps to do it:

  1. ssh -i [PRIVATE_SSH_KEY] -L 3306:localhost:3306  [USER]@REMOTE_HOSTNAME
    (Assuming your mysql server is also on REMOTE_HOSTNAME)
  2. If you are using password based auth then simply use
    ssh  -L 3306:localhost:3306  [USER]@REMOTE_HOSTNAME
  3. open your mysql GUI tool and use these settings (exact layout of ui may depend on your GUI client)
    mysql port forwarding connection settings

This technique can be used for other applications also where you need to connect to some specific port which is not open for remote connections.

Suggested posts:

  1. How to create facebook app for using fbconnect for your website login
  2. How to find python package’s file location
  3. Linux how to modify a user using usermod
  4. Memcache – how to dump all keys and values on command line
  5. How to monitor 404 pages on your site
  6. Java System.out.format examples
  7. Edit a file without changing its timestamp on Linux
  8. Install google camera on Asus m1 max pro
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Linux, Linux Interview Questions, Linux/Unix Command Line, Mysql, SSH, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress