Laravel Sail How to solve SQLSTATE[HY000] [1045] Access denied for user.

Laravel Sail How to solve SQLSTATE[HY000] [1045] Access denied for user.

It seems like you accidentally created a mysql volume by running sail without an .env file, which was persistent the whole time thus of course having no user and database configured.

Execute ./vendor/bin/sail down --rmi all -v to remove all images and volumes and then just ran ./vendor/bin/sail up to recreate the images and volumes.

Laravel Sail is a light-weight command-line interface for interacting with Laravel's default Docker development environment. Sail provides a great starting point for building a Laravel application using PHP, MySQL, and Redis without requiring prior Docker experience.

At its heart, Sail is the docker-compose.yml file and the sail script that is stored at the root of your project. The sail script provides a CLI with convenient methods for interacting with the Docker containers defined by the docker-compose.yml file.

Laravel Sail is supported on macOS, Linux, and Windows (via WSL2).

To know more about sail you can find the official documentation here.

If you find this article helpful please share it with your friends. Also, love to hear your opinions and thoughts on this. You can find me on Twitter.