SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed when trying to connect to DigitalOcean Managed Database

huangapple go评论49阅读模式
英文:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed when trying to connect to DigitalOcean Managed Database

问题

I'm trying to setup a Laravel 10 application on DigitalOcean with a Managed Database. I have an nginx server up and running on the droplet and can access the website by its domain name. However, I can't connect to the Managed Database as can be seen in the screenshot below when I try to migrate the tables.

英文:

I'm trying to setup a Laravel 10 application on DigitalOcean with a Managed Database. I have an nginx server up and running on the droplet and can access the website by it's domainname. However I can't connect to the Managed Database as can be seen in the screenshot below when I try to migrate the tables:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed when trying to connect to DigitalOcean Managed Database

What I have so far is:

These are the settings I use:

.env

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed when trying to connect to DigitalOcean Managed Database

Which come straight from the DO control panel:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed when trying to connect to DigitalOcean Managed Database

/config/database.php

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed when trying to connect to DigitalOcean Managed Database

Location of the CA certificate;

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed when trying to connect to DigitalOcean Managed Database

The MySql client:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed when trying to connect to DigitalOcean Managed Database

Furhtermore I'm able login the mysql server inside the droplet and create database users and tables .

I really would appreciate any help on this. I'm currently kind of clueless after searching for hours on the internet.

答案1

得分: 1

经过长时间的搜索和调试,我发现在 /etc/environment 中已经定义了数据库变量。我猜想在创建Droplet并选中“添加托管数据库”复选框时,DigitalOcean会将其放在那里。然而,我最终删除了它并创建了另一个托管数据库。因此,我应用程序中的 .env 文件中的数据库被 /etc/environment 文件中定义的数据库覆盖了。

英文:

After very long searching and debugging I found that there were already database variables defined in /etc/environment.

I guess DigitalOcean puts it there when you create your droplet and have the "add a managed database" checkbox checked. However I ended up deleting it and creating another managed database.

So the database in my .env file in my application were overruled by the ones defined in the /etc/environment file.

huangapple
  • 本文由 发表于 2023年5月22日 17:59:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76305011.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定