InfoHeap
Tech tutorials, tips, tools and more
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 allow mysql access on AWS/EC2 from a specific IP
  2. Linux – how to add a user using useradd
  3. How to enable telnet program on Windows 10
  4. How to use ssh port forwarding to surf a site from different location
  5. Linux iptables – Nat port forwarding using PREROUTING
  6. Find authentication methods an ssh server supports
  7. Linux – how to enable password login on ssh server
  8. Linux – ssh agent forwarding when using bastion host
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

Follow InfoHeap

facebook
twitter
googleplus
  • Browse site
  • Article Topics
  • Article archives
  • Recent Articles
  • Contact Us
  • Omoney
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | 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

Copyright © 2023 InfoHeap.

Powered by WordPress