Reputation: 21
error:
In AbstractMySQLDriver.php line 112:
An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'symfony'@'localhost' (usin
g password: YES)
In Exception.php line 18:
SQLSTATE[HY000] [1045] Access denied for user 'symfony'@'localhost' (using password: YES)
In PDOConnection.php line 38:
SQLSTATE[HY000] [1045] Access denied for user 'symfony'@'localhost' (using password: YES)
.env : DATABASE_URL=mysql://symfony:[email protected]:3306/symfony?serverVersion=5.7
docker setup: docker-compose.yml
db:
container_name: db
image: 'mysql:8.0'
command: ["--default-authentication-plugin=mysql_native_password"]
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: symfony
MYSQL_USER: symfony
MYSQL_PASSWORD: symfony
DATABASE_URL: symfony.localhost
networks:
- db
Upvotes: 2
Views: 5463
Reputation: 17566
Your connection string should be:
DATABASE_URL=mysql://symfony:symfony@db/symfony?serverVersion=5.7
Tl;dr use db
not localhost
/ 127.0.0.1
for the host part. The db
is the name of the container with MySQL. Docker containers behave like hosts to themselves.
If you don't intend to connect to the MySQL from your host (eg. using MySQL workbench / Sequel Pro) you can drop the ports: 3306:3306
publishing part in the docker-compose
file. It's not needed for the port to work. Containers are allowed to talk to themselves freely within their network to any port.
Upvotes: 1