简体   繁体   English

通过SSH将远程mysql服务器连接到symfony(doctrine)

[英]Connect a remote mysql server to symfony(doctrine) over ssh

im creating a symfony Application and I need access to a database that is on another server(via ssh). 我创建了一个symfony应用程序,我需要访问另一个服务器上的数据库(通过ssh)。 How would I do something like that? 我该怎么做?

I could'nt find any option for that in the doctrine documentation. 我在学说文档中找不到任何选择。

if the database server not open the database port, so you must be use the ssh as the middle protocol like this. 如果数据库服务器没有打开数据库端口,那么您必须将ssh用作这样的中间协议。

$host = 'remote host';
$sshuser = 'ssh user';
$sshpass = 'ssh password';
$dbuser = 'db user';
$dbpass = 'db pass';
$dbname = 'db name';

shell_exec("ssh -p$sshpass ssh -o StrictHostKeyChecking=no -f -L 3307:127.0.0.1:3306 $sshuser@$host");

$dbh = new PDO('mysql:host=127.0.0.1;port=3306;dbname=' .$dbname. '', $dbuser, $dbpass);

then use $dhb to interact with your database. 然后使用$ dhb与您的数据库进行交互。

may be you must write some code on doctrine library for do your idea. 可能是您必须在学说库上写一些代码才能实现自己的想法。

You have to open an SSH tunnel. 您必须打开SSH隧道。

See Can I SSH to MySQL with the GUI tools? 请参阅可以使用GUI工具SSH到MySQL吗? or Access Your MySQL Server Remotely Over SSH . 通过SSH远程访问MySQL服务器

For parameters.yml this looks like a local MySql server, wich menans there's nothing special. 对于parameter.yml,它看起来像本地的MySql服务器,但是没有什么特别的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM