Do you forget the MySQL root password, can’t remember or want to break the password? In simple word, do you want to reset the MySQL database password? Then you came at the right place.
Here we have posted the few lines of command code that will help you to reset your MySQL password in Mac OS X and in Linux too.
So let’s get started.
How to Change the MySQL root Password in Linux or macOS?
Changing the MySQL root password is easy, You just need to follow the below step by step guide and you will be amazed how easy it is.
Note: With the help of below command line you can reset MySQL database password in Linux or OSX as long as you know the root user password of the box you are on, this guide is for MySQL 5.7 onwards.
sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
This will be an ongoing command until the process is finished so open another shell/terminal window, and log in without a password as root:
mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Change the lowercase ‘MyNewPass’ to what you want – and keep the single quotes.
sudo /usr/local/mysql/support-files/mysql.server start
That’s it guys, now your root password will be updated.
Hope you guys like this guide. Don’t forget to share it with your friends and do comment in the comment section how was this guide? Take good care and bye 😉