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]:[MYSQL SERVER TARGET PORT] -N  [email protected]_HOST
for example

ssh -L 8888: -N  [email protected]


Terminal 2, run this command to test the tunnel :

mysql –host= -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


Comments are closed.