我正在使用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=passworddocker-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
发布评论