Forget the Mysql password solution summary

  • 2020-06-23 02:04:59
  • OfStack

Method 1: Use the SET PASSWORD command


mysql -u root

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

Method 2: Use mysqladmin


mysqladmin -u root password "newpass"

If root has already set a password, do the following


mysqladmin -u root password oldpass "newpass"

Method 3: Edit the user table directly with UPDATE


mysql -u root

mysql> use mysql;

mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';

mysql> FLUSH PRIVILEGES;

You can do this when you lose your root password


mysqld_safe --skip-grant-tables&

mysql -u root mysql

mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';

mysql> FLUSH PRIVILEGES;

I hope it helps.


Related articles: