使用SSH通道访问MySQL的方法
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,许多时候当要使用Mysql时,会遇到如下情况:1. 信息比较重要,希望通信被加密。2. 一些端口,比如3306端口,被路由器禁用。对第一个问题的一个比较直接的解决办法就是更改mysql的代码,或者是使
千家信息网最后更新 2026年11月01日使用SSH通道访问MySQL的方法
许多时候当要使用Mysql时,会遇到如下情况:
1. 信息比较重要,希望通信被加密。
2. 一些端口,比如3306端口,被路由器禁用。
对第一个问题的一个比较直接的解决办法就是更改mysql的代码,或者是使用一些证书,不过这种办法显然不是很简单。
相关学习视频教程推荐:mysql视频教程
这里要介绍另外一种方法,就是利用SSH通道来连接远程的Mysql,方法相当简单。
一、建立SSH通道
只需要在本地键入如下命令:
ssh -fNg -L 3307:127.0.0.1:3306 myuser@remotehost.comThe 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
现在,你就可以通过本地连接远程的数据库了,就像访问本地的数据库一样。
mysql -h 127.0.0.1 -P 3307 -u dbuser -p dbThe 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 DaemonA 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 myuser@remotehost.comAnd 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.
以上就是详解如何通过SSH通道来访问MySQL的详细内容,更多请关注其它相关文章!
通道
就是
端口
方法
办法
教程
数据
数据库
视频
重要
代码
信息
内容
可以通过
命令
情况
文章
时候
更多
证书
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技有限公司
广州紫鲸互联网科技有限公司
互联网扶贫科技
互联网下的科技发展
互联网科技公司电话
万达互联网科技
互联网科技论坛
互联网养老 桔豆科技
中国的互联网科技企业的崛起
荆州市昕露互联网络科技有限公司
广西互联网科技孵化中心
亳州好赞互联网科技有限公司
互联网金融科技公司的优势
江苏互联网智能科技软件
上海互联网科技公司ppt
江苏互联网科技小贷
容联科技互联网电商
保山互联网科技靠谱吗
互联网科技大佬云集
黑龙江互联网科技公司
广州为想互联网科技有限公司
河南云网互联网络科技有限公司
互联网科技开发公司
互联网的科技创新
壹账通互联网科技
深圳艾佳互联网科技
滨湖区互联网智能科技产品供应
哈尔滨秒房互联网科技有限公司
阿里互联网科技企业
浙南科技城互联网大厦招聘