我正在使用Laravel 5.0。我想知道如何使用 SSH 访问远程数据库。
数据库.php
'mysql' => [
'driver' => 'mysql',
'host' => 'www.xxxxx.in',
'port' => '2222',
'database' => 'xxxx_xxx',
'username' => 'xxxxx_xx',
'password' => 'xxxx0xx',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
您应该创建 SSH 隧道。
有关SSH隧道的更多信息和一些示例,请参见此处:http://chxo.com/be2/20040511_5667.html
例:
ssh -fNg -L 3307:127.0.0.1:3306 myuser@remotehost.com
mysql -h 127.0.0.1 -P 3307 -u dbuser -p db
当然,然后您需要更改凭据:
'mysql' => [
'driver' => 'mysql',
'host' => 'www.xxxxx.in',
'port' => '3307',
'database' => 'xxxx_xxx',
...
],
正如阿列克谢所说,你需要创建一个SSH隧道。
您还需要将MySQL连接端口转发到本地;就像Alexey所做的那样。
然后在您的 Laravel 配置中,将端口设置为转发端口。因此,在阿列克谢的答案的基础上,您的数据库配置将读取如下
'mysql' => [
'driver' => 'mysql',
'host' => 'www.xxxxx.in',
'port' => '3307',
'database' => 'xxxx_xxx',
'username' => 'xxxxx_xx',
'password' => 'xxxx0xx',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
编辑
万一阿列克谢的答案消失了,这些是我答案的相关部分
创建 ssh 隧道
ssh -fNg -L 3307:127.0.0.1:3306 myuser@remotehost.com
使用 进行本地连接
mysql -h 127.0.0.1 -P 3307 -u dbuser -p db