SQLState [HY000]与码头工人的连接拒绝Laravel

编程入门 行业动态 更新时间:2024-10-26 08:30:03
本文介绍了SQLState [HY000]与码头工人的连接拒绝Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Docker在本地计算机上设置现有的Laravel项目.我意识到类似的问题已经问了很多次了,常见的克制是将 DB_HOST 更改为 127.0.0.1 ",但是,我的项目已经设置了该问题.

I'm setting up an existing Laravel project on my local machine using Docker. I realize similar questions have been asked many different times and the common refrain is "change DB_HOST to 127.0.0.1, however, my project already has that set.

每当我尝试运行: docker-compose exec app php artisan migration:install 设置数据库时,我会收到此错误:

Whenever I try to run: docker-compose exec app php artisan migrate:install to set the DB up I get this error:

In Connection.php line 664: SQLSTATE[HY000] [2002] Connection refused (SQL: create table `migrations` (`id` int unsigned not null auto_increment prima ry key, `migration` varchar(255) not null, `batch` int not null) default character set utf8mb4 collate utf8mb4_unicode_ci) In Connector.php line 67: SQLSTATE[HY000] [2002] Connection refused

.env:

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3385* DB_DATABASE=project DB_USERNAME=user DB_PASSWORD=password

docker-compose.yml:

docker-compose.yml:

services: ... mysql: image: mysql:5.5 ports: - 3385:3306 environment: - MYSQL_ROOT_PASSWORD=root - MYSQL_DATABASE=project - MYSQL_USER=user - MYSQL_PASSWORD=password volumes: - data:/var/lib/mysql

使用上述凭据,我能够通过SQLPro或 docker-compose exec mysql bash 之类的工具成功连接到数据库.我知道这很可能是配置问题,但是我不确定问题是什么,Laravel,实际上是PHP世界,不是我的专长.

Using the above credentials I am able to successfully connect to the database through a tool like SQLPro or docker-compose exec mysql bash. I know this is likely a configuration issue but I'm not sure what the problem is, Laravel, and really the PHP world, are not my forte.

*这不是默认端口,默认端口也不起作用,我更改了端口号,以免与我在本地运行的MySQL实例冲突.

*This is not the default port, the default port dosen't work either, I changed the port number so it wouldn't conflict with an instance of MySQL I have running locally.

推荐答案

您的 app 容器服务将需要连接到 mysql:3306 ,所以

Your app container service would need to connect to mysql:3306, so

DB_HOST=mysql DB_PORT=3306

如果不需要从主机连接到MySQL,则根本不需要 ports 部分.

If you don't need to connect to MySQL from the host, then you don't need the ports section at all.

更多推荐

SQLState [HY000]与码头工人的连接拒绝Laravel

本文发布于:2023-10-26 01:15:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528645.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:码头   工人   SQLState   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!