I am trying to setup Laravel Sail environment on the server, and after doing the same setup that works locally on my machine along with the .env file
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE="dbname"
DB_USERNAME="sail"
DB_PASSWORD="password"
This is my docker-compose that once again works locally
mysql:
image: 'mysql:8.0.36'
command: --default-authentication-plugin=mysql_native_password --skip-grant-tables
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
restart: always
volumes:
- 'sail-mysql:/var/lib/mysql'
networks:
- sail
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
restart: always
volumes:
- 'sail-redis:/data'
networks:
- sail
healthcheck:
test:
- CMD
- redis-cli
- ping
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
volumes:
sail-mysql:
driver: local
I tried the following
- Deleted all containers, images and volumes using
docker system prune -a - Changed the password from default to root
- Changed both the username and password to root (Removed "" from .env also)
- When trying to access mysql via
sail shellI get the following lineERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) - Chaned
DB_HOSTindatabase.phpfrom default tomysql
Note: this is Ubuntu 22.04 server running on digital ocean droplet.
I always get the same error which is
SQLSTATE[HY000] [2002] Connection refused
also docker ps returns a healty mysql container running:
mysql:8.0.36 "docker-entrypoint.s…" 11 minutes ago Up 11 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp nlonetwork_local-mysql-1