Access your remote MySQL server, which only allow MySQL connections from our bastion host

How access your remote MySQL server, which only allow MySQL connections from our bastion host and we would like to access that MySQL via the Bastion Server with a SSH Tunnel from our pc.

Setup the SSH Tunnel

Establish the tunnel:

ssh -f -p 22 me@bastion.domain.example -L 3306:remote-mysql.domain.example:3306 -N

Save the pid as an environment variable:

db_mysql_tunnel_pid=$(ps aux | grep '3306:remote-mysql.domain.example:3306' | grep -v grep | awk '{print $2}')

Now that our tunnel has been established, access mysql via the ssh tunnel:

mysql -u user -p --host=localhosy --port=3306

Mysql console:

mysql> 

For close the ssh tunnel:

$ kill ${db_mysql_tunnel_pid}

Original

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

 

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.