Posted on under Laravel by Owen Conti.
I recently started running into this error on GitHub Actions out of the blue:
Failed to initialize, mysql service is unhealthy
It turns out, the MySQL docker image had been recently updated to no longer support setting the
MYSQL_USER
environment variable to
root
, since there is already a root user created by default.
To get around this issue, all you have to do is choose a different name for your
MYSQL_USER
:
1services: 2 mysql: 3 image: mysql:8 4 env: 5 MYSQL_USER: laravel_user 6 MYSQL_PASSWORD: laravel_pass 7 MYSQL_ROOT_PASSWORD: root 8 MYSQL_DATABASE: laravel_db 9 ports:10 - 3306:330611 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
For reference, this is how I had it setup prior to the change:
1services: 2 mysql: 3 image: mysql:8 4 env: 5 MYSQL_USER: root 6 MYSQL_PASSWORD: root 7 MYSQL_ROOT_PASSWORD: root 8 MYSQL_DATABASE: laravel_db 9 ports:10 - 3306:330611 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
Hopefully you found this article useful! If you did, share it on X!
Found an issue with the article? Submit your edits against the repository.