- 将mysql_host:3306的数据库连接转发到本地的3309端口
ssh -fNg -v -L 3309:mysql_host:3306 root@jump_host
- 通过mysql命令连接数据库
mysql -h 127.0.0.1 -u mysql_user -P 3309 -p
- 注意,这里转发的时候看看端口,如果端口被占用可能一直连不上,可以使用
-v
参数查看连接的详情数据
debug1: Local forwarding listening on :: port 3307.
bind [::]:3307: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 3307
Could not request local forwarding.
debug1: Requesting no-more-sessions@openssh.com
debug1: forking to background
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0