How to Reset or Recover Forgotten mySql root Password

Recover Forgotten mySql root Password in Linux

  • Step 1 – Locate my.ini or my.cnf in mysql server.
  • Step 2 – Edit my.ini or my.cnf and insert ‘skip-grant-tables’ below [mysqld]
  • Step 3 – Restart MySQL
  • Step 4 – Set new password for your root user by running
$ mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
mysql> UPDATE mysql.user SET Password=PASSWORD('new-password-here') WHERE USER='root' AND Host='localhost';


in phpMyAdmin in the mysql database (or just leave it like this if MySQL cannot be accessed from remote hosts)
  • Step 5 – Remove the skip-grant-tables in the my.ini or my.cnf file
  • Step 6 – Restart MySQL

Resetting MySQL Root Password with XAMPP on Localhost

How to change a mysql user password?

$ mysql -u root -p
mysql> use mysql;

- The syntax is as follows for mysql database server version 5.7.5 or older:
mysql> SET PASSWORD FOR 'user-name-here'@'hostname' = PASSWORD('new-password');

- For mysql database server version 5.7.6 or newer use the following syntax:
mysql> ALTER USER 'user'@'hostname' IDENTIFIED BY 'newPass';

- You can also use the following sql syntax:
mysql> UPDATE mysql.user SET Password=PASSWORD('new-password-here') WHERE USER='user-name-here' AND Host='host-name-here';

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'sjh643#22SLKhaA2%';
mysql> FLUSH PRIVILEGES;

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x