英文:
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=<username>
DB_PASSWORD=<password>
//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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论