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.

    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏