首页 > 解决方案 > 我需要帮助在 laravel 中为 digitalocean 管理的数据库建立连接

问题描述

我创建了一个 mysql 集群,但在建立数据库和我的项目之间的连接时遇到了问题。

标签: laravel

解决方案


在 DigitalOcen 中创建数据库和用户,然后运行以下命令:

GRANT ALL ON DB_NAME TO 'USER_NAME'@'%' WITH GRANT OPTION; ALTER USER 'USER_NAME' IDENTIFIED WITH mysql_native_password BY 'GIVE_THE_PASSWORD';

Laravel 连接:

DB_CONNECTION=mysql
DB_HOST=As given on DO managed DB
DB_PORT=As given on DO managed DB
DB_DATABASE=give the name of the database that you created within DO and want to use here
DB_USERNAME=give the name of the user that you created within DO and want to use here
DB_PASSWORD=give the pass of the database that has been created automatically while create DB

推荐阅读