Reset Mysql root user password Linux and Mac OSX in terminal

Reset Mysql root user password Linux and Mac OSX in terminal

Most of the time we follow the steps to install MySQL using copy and paste the code in terminal or command line. When we try to log in again MySQL we forgot root user password and we can’t login next time. Here I will share how to reset MySQL root user password and next how we can reset and change root user password. We can reset root user password using the same command in Linux or MacOS Sierra and OSX. Here I’m using the code of MySQL 5.7
  1. Stop MySQL
sudo /usr/local/mysql/support-files/mysql.server stop
Start command in safe mode:
sudo mysqld_safe —skip-grant-tables
This command will start a process until we stop the process. This process helps us to enter MySQL using root user without password. Open a new window of terminal or command line. We can use a new tab of the command line or terminal to open a clean new shell in MacOS Sierra and OSX also Linux.
  1. Reset root user password
mysql -u root


ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘YourNewPassword’;
‘YourNewPassword’ is the new password of your MySQL root user password. We can set any password as we want. After that, we will quit MySQL shell to command line shell. Type the code below to quit MySQL.
  1. Start MySQL
sudo /usr/local/mysql/support-files/mysql.server start
We have done successfully change MySQL root user password without knowing the password.

Leave a Comment

Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.

Not readable? Change text. captcha txt
Free VestaCP File Manager, reset mysql