Laravel Planetscale可以进行迁移,但无法查询,显示SQLSTATE[HY000] [2002]。

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

Laravel Planetscale can migrate but can't query it show SQLSTATE[HY000] [2002]

问题

我在使用 Laravel 版本 8.0 和 PlanetScale 连接时遇到了一些问题。我已经在我的 .env 文件中配置了所有内容,包括证书安装,并且可以顺利迁移表格到数据库。但是,当我尝试查询数据库时,我一直收到一个错误消息,上面写着 Illuminate\Database\QueryException.SQLSTATE[HY000] [2002] (SQL: select * from company_user)

以下是我从 PlanetScale 复制的 .env 配置:

DB_CONNECTION=mysql
DB_HOST=aws.connect.psdb.cloud
DB_PORT=3306
DB_DATABASE=business_directory
DB_USERNAME=<username>
DB_PASSWORD=<password>
//cacert.pem 在根目录中
MYSQL_ATTR_SSL_CA=cacert.pem

我已经尝试了自己排除这个问题,但到目前为止没有任何效果。我已经仔细检查了所有的配置设置,并确保一切都正确,但似乎还是无法工作。

是否有其他人遇到过这个问题?如果是的话,你有没有任何修复建议?非常感谢任何帮助!

提前致谢。

PS. 我已经尝试在我的本地主机上迁移表格,插入和查询数据,一切正常。

英文:

I'm having a bit of trouble with my Laravel version 8.0 and PlanetScale connection. I've got everything configured in my .env file, including the certificate installation, and I can migrate tables to the database just fine. However, when I try to query the database, I keep getting an error message that says Illuminate\Database\QueryException.SQLSTATE[HY000] [2002] (SQL: select * from company_user)

These are the .env configuration I copied from planetscale

DB_CONNECTION=mysql
DB_HOST=aws.connect.psdb.cloud
DB_PORT=3306
DB_DATABASE=business_directory
DB_USERNAME=&lt;username&gt;
DB_PASSWORD=&lt;password&gt;
//cacert.pem is inside the root directory
MYSQL_ATTR_SSL_CA=cacert.pem

I've tried troubleshooting this issue on my own, but so far nothing has worked. I've double-checked all of my configuration settings and made sure that everything is correct, but I still can't seem to get it to work.

Has anyone else experienced this issue before? If so, do you have any suggestions for how to fix it? Any help would be greatly appreciated!

Thanks in advance.

PS. I have tried migrating tables, insert and query data from my localhost it work just fine.

答案1

得分: 0

为了留下一个解决方案,以供将来可能遇到此问题的人使用,以下是解决我的问题的解决方案。

Planetscale要求Windows用户自行下载SSL证书。我确实下载了SSL证书,但将其放在了错误的文件夹中。
应该将cacert.pem文件放在公共文件夹中,而不是根文件夹中。

//cacert.pem应该放在public文件夹中,而不是根文件夹中。
MYSQL_ATTR_SSL_CA=cacert.pem
英文:

To leave a solution for people who might face this issue in the future this is the solution that solved my problem.

Planetscale require window user to download SSL certificate on our own. and I did download the SSL certificate but placed in the wrong folder.
Instead of placing in the root directory, the cacert.pem file should be placed in public folder.

//cacert.pem should be in public folder instead of root folder.
MYSQL_ATTR_SSL_CA=cacert.pem

huangapple
  • 本文由 发表于 2023年6月1日 01:42:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76376067.html
匿名

发表评论

匿名网友

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

确定