I have a laravel app and I wanted to use a webserver mysql database (here I used docker). But I have a very bad time trying to make it work. I tried at least 10 different docker-compose and I face the same problem :
SQLSTATE[HY000] [1130] Host 'app.acti_app-network' is not allowed to connect to this MySQL server
Here is my docker-compose:
version: '3.7'
services:
# PHP-FPM - Service
app:
build:
context: .
dockerfile: Dockerfile
container_name: app
restart: unless-stopped
tty: true
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker-files/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
# NGINX - Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "8100:80"
- "8143:443"
volumes:
- ./:/var/www
- ./docker-files/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
# MySql - Service
db:
image: mysql:8.0
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: 123456
MYSQL_ROOT_HOST: '%'
volumes:
- mysqldbdata:/var/lib/mysql
- ./docker-files/mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
# Volumes
volumes:
mysqldbdata:
driver: local
# Networks
networks:
app-network:
driver: bridge
I know this going to help. This is what Select Host Query returnig:
mysql> SELECT host, user FROM mysql.user;
----------- ------------------
| host | user |
----------- ------------------
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
----------- ------------------
CodePudding user response:
you can try create a user for % login
CodePudding user response:
For better security, use root user only for administrative purpose and create another user with limited access for use by the application. For creating separate user, you can follow this answer: https://stackoverflow.com/a/59653823/93794