内容目录
Hyperf框架连接MySQL报错:
[ERROR] SQLSTATE[HY000] [2002] No such file or directory (SQL: SELECT * FROM
user
)[1082] in /data/project/hyperf-skeleton/vendor/hyperf/database/src/Connection.php[ERROR] #0 /data/project/hyperf-skeleton/vendor/hyperf/database/src/Connection.php(1039): Hyperf\Database\Connection->runQueryCallback()
- 原因是:MySQL服务器拒绝访问
解决方法:在
项目地址/hyperf-skeleton
目录下打开配置文件.env将 DB_HOST=localhost 改为DB_HOST=myMysql
或者将 REDIS_HOST=localhost 改为 REDIS_HOST=连接的MySQL容器的IP (Docker环境下查询MySQL容器IP方法)
- 然后配置对应的DB_PORT端口,DB_USERNAME用户名和DB_PASSWORD密码
.env配置文件内database配置修改如下:
DB_DRIVER=mysql DB_HOST=172.19.0.4 //DB_HOST=myMysql DB_PORT=3306 DB_DATABASE=hyperf DB_USERNAME=root DB_PASSWORD=123456 DB_CHARSET=utf8mb4 DB_COLLATION=utf8mb4_unicode_ci DB_PREFIX=
然后进入容器并启动 Hyperf 服务
docker exec -it myhyperf /bin/sh
cd /data/project/hyperf-skeleton
php bin/hyperf.php start
重新查看运行结果
0 条评论
撰写评论