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:
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
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.
That will work. Still, not sure if this is the correct/best way to solve my issue.
You need to change database info in your
.env
file then run these commands