linux或mac下,通过本机访问远程mysql数据库(数据库本身未开启远程访问权限)

1、使用ssh forward,将远程服务器的3306端口转发到本机

ssh -nNT -L 3306:localhost:3306  user@remote_db_server

注意,不要关闭本机的terminal


2、检查是否成功:

linux下,执行命令:netstat -antp|grep 3306

mac下,执行命令:lsof -n -i:3306 | grep LISTEN