skip to Main Content

I’m stucked on a stupid problem.. Maybe I shouldn’t even bother about it, but I want to understand.

I’m using Laravel with Sail/Docker, on macos.
I’d like to change my DB user and password, just to try and test.
If I change them in .env config (sail2/password2), then shut down sail and then sail up -d (or even completely rebuild the containers), I see that:

  • Laravel is recognizing the new user (sail2), since if I tinker this:

     DB::select("select * from users");
    

It’s going to complain like this:

SQLSTATE[HY000] [1045] Access denied for user 'sail2'@'172.20.0.7'

So Laravel knows the new user, but the user has no access to the database.

  • Docker itself does recognize the new credentials, since by inspecting the mysql container I can see this:

enter image description here

Therefore, what I can say is that it all works except the fact that the new user seems not to be assigned to the current database.
Please note I also tried to connect with Sequel Ace and Table Plus, but doesn’t work. Instead, they will connect with the original credentials (sail/password).

Why? And how to solve?

2

Answers


  1. Chosen as BEST ANSWER

    I've just found at least a partial solution. Basically, from Docker I can log into the database server as root and from there I can manually add whichever user I want. So, from Docker > click the mysql container and the click exec.

    Then log in as root. Then add the new user and grant privileges.

    mysql> create user 'sail2'@'%' identified by 'password2';
    mysql> grant all on mytestsite.* to 'sail2'@'%';
    

    That will work. Still, not sure if this is the correct/best way to solve my issue.


  2. You need to change database info in your .env file then run these commands

    # bring the sail down
    sail down -v
    
    # remove cache and re-build
    sail build --no-cache
    
    # bring the sail up
    sail up -d
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search