mysql workbench – ssh – putty – port forwarding

原帖地址: http://techzhiqi.no-ip.org/blog/?p=17

mysql workbench 连接设置是初进IT公司的新人必须掌握的基本技能。我们公司的环境:mysql server running on machine_A (Centos 6), mysql workbench installed on individual laptop(Win7). 下面给出4种常见场景下的连接方案。

1. mysql账号允许远程登录&&machine_A(ip=192.168.10.100) allow incoming traffic on tcp:3306

select connection method: Standard(TCP/IP)

select connection method: Standard(TCP/IP)

这种场景最简单,选择连接方式为Standard(TCP/IP), 填入machine_A的ip,mysql账户名和密码即可。但是服务器的这种设置很不安全,mysql管理员往往会限制用户的登陆地址为本地,即从运行mysql server的机器上登陆数据库。

2. 用户必须从machine_A本地登陆数据库&&你在machine_A上有一个ssh账号。

select connection method: "Standard TCP/IP over SSH"

select connection method: “Standard TCP/IP over SSH”

对于数据库来说,安全性提高了。因为就算数据库账号密码泄露,只要machine_A(ssh server)的账号密码没有泄露,数据库还是安全的。但是服务器管理员(IT administrator)出于安全考虑,可能会限制登陆该服务器的用户。比如只给几个核心员工登陆machine_A的权限,这种情况下IT administrator会提供另一台不那么敏感的machine_B供你登陆。

3. mysql server运行在machine_A,machine_A允许incoming traffic on port 3306, 你有一个ssh account在machine_B(ip=192.168.10.10),数据库允许your account从machine_B登陆。

figure for scenario3

figure for scenario3

SSH Hostname填machine_B的ip,MySQL Hostname填machine_A的ip。从数据库管来看,安全性与场景2相同,但是machine_A的安全性得到提高。但是这还不够,IT administrator往往还会限制用户对machine_B的访问,比如只允许内网登陆,或者machine_B根本没有公网ip。如果你们公司允许远程工作的话,往往会在内网内提供一台机器(machine_C)供外网登陆。这就是第四种场景。

4. mysql server运行在machine_A,machine_A允许incoming traffic on port 3306, 你有一个ssh_account_B在machine_B(ip=192.168.10.10),另一个ssh_account_C在machine_C(publc ip=85.23.10.4, private ip=192.168.10.2), machine_B允许从machine_C的ssh登陆,数据库允许你的mysql account从machine_B登陆。这种场景下,你需要用到putty和ssh的port forwarding功能。

create session in putty

create session in putty

Then open the session, log into machine_C, and type this command:

ssh -L 5555:192.168.10.100:3306 192.168.10.10

This command means all requests sent to machine_C’s port 5555, will be forwarded to machine_A’s port 3306. And from the view of machine_A, it will just see the queries come from machine_B. Then you’ll be asked to log into you ssh account on machine_B. After log in to machine_B, the port forwarding is set up.We still need to set the mysql workbench so that the queries from the workbench will be forwarded to machine_C’s port 5555. port forwarding这个概念有点不好想,就这行命令来讲就是:所有发送给C机器5555端口的包都通过B转发给A的3306端口,并且A机器认为该请求是从B机器发起的,并不知道C机器的存在。

figure for scenario4, setting in the workbench

figure for scenario4, setting in the workbench

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值