导航:首页 > 编程大全 > mysqlssh数据库

mysqlssh数据库

发布时间:2025-02-07 07:16:07

A. 如何通过SSH通道来访问MySQL


许多时候当要使用Mysql时,会遇到如下情况: 出于数据库的安全性,数据库管理员在配置数据库时会为数据库增加一层保护伞,保护用户在连接数据库时的安全和信息不被泄漏,通常的做法就是配置SSH,也就是为数据库增加一个安全协议,这也导致了用户进行远程连接



许多时候当要使用Mysql时,会遇到如下情况:

出于数据库的安全性,数据库管理员在配置数据库时会为数据库增加一层“保护伞”,保护用户在连接数据库时的安全和信息不被泄漏,通常的做法就是配置SSH,也就是为数据库增加一个安全协议,这也导致了用户进行远程连接时的困难。
1. 信息比较重要,希望通信被加密。
2. 一些端口,比如3306端口,被路由器禁用。

对第一个问题的一个比较直接的解决办法就是更改mysql的代码,或者是使用一些证书,不过这种办法显然不是很简单。

这里要介绍另外一种方法,就是利用SSH通道来连接远程的Mysql,方法相当简单。

一 建立SSH通道

例如:

远程Mysql服务器ip:172.21.20.203

mysql端口号:3307 用户名:test 密码:123456

SSH通道IP:117.123.52.161 端口:79

用户名:admin

通过navicat for mysql客户端工具,

通常我们普通连接就是如下:



点击连接测试:弹出错误框,由于添加了SSH协议!所以我们要使用SSH通道,如下图:



这时候点击连接测试,,可以连接进去,Test Success.

只需要在本地键入如下命令:

ssh -fNg -L 3307:127.0.0.1:3306 [email protected]

The command tells ssh to log in to remotehost.com as myuser, go into the background (-f) and not execute any remote command (-N), and set up port-forwarding (-L localport:localhost:remoteport ). In this case, we forward port 3307 on localhost to port 3306 on remotehost.com.

二 连接Mysql

例如:我们在终端输入:

ssh -fNg -p 79 -L 8989:172.21.20.203:3307 [email protected]

现在,你就可以通过本地连接远程的数据库了,就像访问本地的数据库一样。



点击连接,Test Success

mysql -h 127.0.0.1 -P 3307 -u dbuser -p db

The command tells the local MySQL client to connect to localhost port 3307 (which is forwarded via ssh to remotehost.com:3306). The exchange of data between client and server is now sent over the encrypted ssh connection.

或者用Mysql Query Brower来访问Client的3307端口。

类似的,用PHP访问:



Making It A Daemon

A quick and dirty way to make sure the connection runs on startup and respawns on failure is to add it to /etc/inittab and have the init process (the, uh, kernel) keep it going.

Add the following to /etc/inittab on each client:

sm:345:respawn:/usr/bin/ssh -Ng -L 3307:127.0.0.1:3306 [email protected]

And that should be all you need to do. Send init the HUP signal ( kill -HUP 1 ) to make it reload the configuration. To turn it off, comment out the line and HUP init again.

阅读全文

与mysqlssh数据库相关的资料

热点内容
手机qq临时会话代码 浏览:415
陈晓陈妍希2016app 浏览:67
襄樊儿童编程有什么作用 浏览:64
同时打印多个pdf文件 浏览:823
c编译中找不到制定文件 浏览:139
linuxjvm进程监控 浏览:152
小米分类文件找不到 浏览:901
电脑怎么手动获取网络 浏览:317
五行生财app如何 浏览:541
文件管理图标丢失 浏览:500
返利网站怎么经营 浏览:738
plc编程时有什么技巧 浏览:276
小苹果爵士 浏览:156
镜像助手找不到boot文件 浏览:506
桌面保护密码怎么设置 浏览:895
smit工具的log文件有哪些 浏览:883
做网站运营要多少钱 浏览:933
放在桌面上的文件在c盘 浏览:530
哪个app的东西是专柜的 浏览:380
韩剧在哪里看app 浏览:40

友情链接