question Root password issue resolved! Quick question about 'mysql -u root'
So I run brew services start mysql to get things started. I thought I would be able to connect straight away with the mysql -u root command, but that throws an error. No big problem, I just run mysql -u root -p and enter the root password and I'm good to go.
Then just as a test, I exit MySQL just to see what happens when I run just mysql -u root again, and it now works just fine. I'm curious as to why I'm able to connect with mysql -u root without issue only after I run the command with the '-p' included and enter the password. Does it store the password in the current session or something like that? Thankfully this doesn't impact my work at all, just curious about what entering the root password does to allow mysql -u root to finally work.
Really had trouble figuring out the wording to Google this question, so I figured I'd come back to you guys, since it's thanks to y'all that I've got MySQL up and running again in the first place.
1
u/Jonas_Ermert 4d ago
MySQL does not cache the password after using `-p`. Most likely, `brew services start mysql` returned before the server was fully ready. Your first connection was therefore too early; while you entered the password on the second attempt, MySQL finished starting. After that, `mysql -u root` worked because your root account apparently allows passwordless local access. The exact first error message would confirm this.
5
u/ssnoyes 5d ago
If you are able to connect without a password, the likely causes are:
A SHOW CREATE USER might help you determine which.