Skip to content

[Linux] Connect to Mysql through SSH Tunnel

let’s say you’re going to connect to mysql database server but the database not open to public (security reason), there is workaround to perform this through ssh tunnel

first, open 2 terminal window, then on

Terminal 1, run this command :

ssh -L [YOUR DESIRED PORT]:[localhost or 127.0.0.1]:[MYSQL SERVER TARGET PORT] -N  SSH_USERNAME@SERVER_HOST
for example

ssh -L 8888:127.0.0.1:3306 -N  [email protected]

 

Terminal 2, run this command to test the tunnel :

mysql –host=127.0.0.1 -P 8888 -uMYSQLUSER -pPASSWORD

 

like on termanl 2 later you can connect us mysql gui tools like navicat, mysql bench, or any your fav tools

Share

Comments are closed.