stratboy's avatar

How to change sail DB user and password?

Hi! It seems that with a sail installation is not so simple to change DB user and password. It always uses the sail/password defaults. By changing values in .env file, nothing happens, even after restarting or rebuilding the docker containers. So how to?

0 likes
6 replies
LaryAI's avatar
Level 58

To change the DB user and password in a Sail installation, you need to update the .env file and then rebuild the Docker containers.

Here are the steps to follow:

  1. Open the .env file in the root directory of your Laravel project.
  2. Locate the DB_USERNAME and DB_PASSWORD variables.
  3. Update the values of these variables with the desired DB user and password.
  4. Save the changes to the .env file.
  5. In your terminal, navigate to the root directory of your Laravel project.
  6. Run the following command to rebuild the Docker containers:
sail build --no-cache
  1. After the containers have been rebuilt, run the following command to restart the containers:
sail up -d

Now, the DB user and password should be updated and used by your Sail installation.

If you're still experiencing issues, make sure that you're updating the correct .env file and that you're running the commands from the correct directory.

stratboy's avatar

It seems it doesn't work. At least with my installation.

stratboy's avatar

It's strange: if I do:

sail mysql

I get

ERROR 1045 (28000): Access denied for user 'sail2'@'localhost' (using password: YES)

So it reads the new user (sail2) from .env, but the user is not allowed to access the db.

brychanmd's avatar

I have the same issue, the solution above does not work either. I can only successfully run the sql docker container when the details in the .env are default.

puklipo's avatar
  1. Change .env
  2. Delete docker volume.

Docker Desktop

Search in Volumes

cli

docker volume ls

DRIVER    VOLUME NAME
local     example-app_sail-mysql
docker volume rm example-app_sail-mysql
SmereKa's avatar

@puklipo don't forget after deleting the volume, run one more time

sail artisan migrate

Please or to participate in this conversation.