doujiu8918 2016-07-15 09:46
浏览 266

使用SSH隧道连接使用“localhost”连接到远程mysql服务器

Hey I'm a bit new to this kind of thing, I hope the title makes sense.

Basically I have a mysql server running on a LAMP stack, with some mean legacy code, by which all connections to the database are using mysql_connect("localhost", "user", "pass"). (I know it's bad, I didn't write it!).

I would like to run my own local version of our website for debugging/dev purposes, but I can't figure out how to connect to our database (we have a test-database running remotely that is updated every day with the live data). I have tried remotely connecting but I can't figure it out.

I was wondering if I keep the code (with "localhost" connection written in), and use some kind of SSH tunneling to "trick" the code into connecting to the remote database? Or would it perhaps be easier to set up some kind of mysql 'server' on my local machine? Using phpstorm's in built "database" functionality, I managed to connect to our database using ssh tunneling, but from there I'm completely lost. Again I'm new to this, so I apologise if this sounds very naive.

Any kind of help for a solution would be great.

  • 写回答

1条回答 默认 最新

  • doubanduo7620 2016-07-15 10:04
    关注

    If you are on Linux you must install Stunnel on both Client and Server.

    Take a look here: https://blog.thesysadmins.co.uk/using-stunnel-to-encrypt-unsecure-connections.html

    By configuring properly Stunnel you will be able to use mysqli_connect with "locahost" while actually referring to a remote server.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题