1. mysql账号允许远程登录&&machine_A(ip=192.168.10.100) allow incoming traffic on tcp:3306
这种场景最简单,选择连接方式为Standard(TCP/IP), 填入machine_A的ip,mysql账户名和密码即可。但是服务器的这种设置很不安全,mysql管理员往往会限制用户的登陆地址为本地,即从运行mysql server的机器上登陆数据库。
2. 用户必须从machine_A本地登陆数据库&&你在machine_A上有一个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登陆。
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功能。
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机器的存在。