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.
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:
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
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.
*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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…