[MySQL] A Comprehensive Guide to MySQL Password Errors
Problem
Access denied for user 'root'@'localhost' (using password: YES)
If it says 'No', it means that a password was not entered. If it says 'Yes', it means that the password entered was incorrect.
I am sure I entered the correct password, but the error keeps occurring. I don't know how many times I've tried. It was simply incomprehensible.
[Solution1 - MySql root password Reset Master Solution]
> **MacOSX MySql root Password Reset master solution**
> **Step by step guide-**
> $ brew services stop mysql
> $ pkill mysqld
> $ rm -rf /usr/local/var/mysql/ ****# NOTE: this will delete your existing database!!!****
> $ brew postinstall mysql
> $ brew services restart mysql
> $ mysql -u root
Please be aware that if you proceed with the above method, the MySQL database will be initialized.
[Solution - Final]
Only this method worked on my MacBook.
brew update
brew install mysql
If you’d old mysql you can either upgrade with brew or reinstall completely.
brew outdated
brew upgrade mysql
After backing up existing databases with the method you’d chosen, we can now safely remove old sql and install new one.
brew uninstall mysql
brew cleanup
brew update
brew install mysql
Now we can check our installation by brew service.
brew services list
Reset with skip grant tables (mac)
Step1: you can simply stop mysql service & restart with skip grant parameter
brew services stop mysql
We bypass the loading of the grant table in MySQL 8.0.x, which, in turn, automatically activates — skip-networking, disallowing remote connections.
mysqld_safe --skip-grant-tables &
Step2: Now you will be in mysql command prompt or just type “mysql”. Linux user can start resume from this command.
$ mysql
Welcome to the MySQL monitor etc .....
......
Step3: we'll utilize the mysql databases (meta database), which is the default database that stores various meta information, help, InnoDB records, proxy, plugins, and master & slave records.
mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEWPASSWORD';
If we don’t flush the privileges mysql cli will prompt “MySQL server is running with the — skip-grant-tables option so it cannot execute this statement”. You won’t find such error after following above step, please remember to replace NEWPASSWORD with your desire password.
Step4: Finally you can restart(linux) or start MySQL and login with given password.
brew services restart mysql // Mac
Reference
https://aungzanbaw.medium.com/how-to-reset-root-user-password-in-mysql-8-0-a5c328d098a8