使用 SSH 连接 Laravel MySql 数据库
问题描述
我有几个想要访问的远程数据库,但它们位于只能通过 SSH 使用密钥访问的服务器上.
I have a couple of remote databases I would like to access, but they are sitting on a server accessible only through SSH with a key.
在 Sequel Pro 中,我像这样连接到这个远程数据库:
In Sequel Pro, I connect to this remote DB something like this:
我将如何配置我的 Laravel 应用程序以连接到这样的数据库?
How would I configure my Laravel app to connect to such a DB?
推荐答案
这里有一个可行的解决方案,它通过带密钥的 SSH 处理托管在 EC2 实例上的数据库.
Here's a workable solution of working with a database hosted on an EC2 instance via SSH w/ a key.
首先,在你的数据库配置中设置一个对应的连接:
First, setup a corresponding connection in your database config:
二、建立隧道:
(我们将SSH密钥传递给i参数,建立SSH连接,绑定13306端口)
(we pass in the SSH key to the i parameter and establish an SSH connection, binding to port 13306)
第三,像通常在 Laravel 应用程序中一样使用数据库:
Third, use the DB how you normally would in a Laravel App:
这篇关于使用 SSH 连接 Laravel MySql 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!