'How to fix a Laravel Sail "SQLSTATE[HY000] [1130] Host 'XXX.XXX.X.X' is not allowed to connect to this MySQL server" error
Laravel: 9.2
Mac OS: 12.3.1
Docker Desktop: 4.5.0
I have installed a default Laravel project using sail. My docker-compose.yml file includes the following:
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
And my default environment variables are:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=example_2012
DB_USERNAME=sail
DB_PASSWORD=password
But when I try to connect to the database from sail artisan and http://localhost. I receive the following error:
Host 'XXX.XXX.X.X' is not allowed to connect to this MySQL server"
"docker ps -a | grep mysql" returns:
XXXXXXXXXXXX mysql/mysql-server:8.0 "/entrypoint.sh mysq…" 3 minutes ago Up 3 minutes (healthy) 33060-33061/tcp, 0.0.0.0:3308->3306/tcp example-2022_mysql_1
I've tried amending the ports to 3307 but without success.
Solution 1:[1]
According to your output it should be port 3308 which is forwarded to 3306 in the container
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | online Thomas |