For some reason MySQL stopped giving access for root. Uninstalled and reinstalled with Homebrew. Fresh install, fresh tables but when I enter
mysql -u root -
I had this problem on a fresh install on Mac. I installed MariaDB with:
brew install mariadb
Then started the service:
brew services start mariadb
I was unable to run 'mysql_secure_installation' as it prompted for the root password. Then I noticed in the install output:
mysql_install_db --verbose --user=jonny --basedir=/usr/local/Cellar/ ....
So I tried logging in as the username specified in the mysql_install_db output and was successful e.g.
mysql -u jonny
Then at the mysql prompt if you want to set a password for the root user:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('ToPsEcReT');
Got this error after installing mysql via home brew.
So first remove the installation. Then Reinstall via Homebrew
brew update
brew doctor
brew install mysql
Then restart mysql service
mysql.server restart
Then run this command to set your new root password.
mysql_secure_installation
Finally it will ask to reload the privileges. Say yes. Then login to mysql again. And use the new password you have set.
mysql -u root -p
I've just noticed something common to most of the answers here, and confirmed on my fresh install. It's actually obvious if you look at the recommendations to run mysqladmin -u root
without -p
.
There is no password.
Brew sets mysql up with just a root user and no password at all. This makes sense, I guess, but the post-install Caveats don't mention it at all.