This article mainly shares with you some methods of changing the root password of MySQL, hoping to help everyone.
Method 1: Use the SET PASSWORD command
mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
mysql> quit; //Exit the mysql console
After setting the password, test login:
mysql -u root -p"newpass" //-p and password There must be no spaces between them
Or enter mysql -u root -p and press Enter to let the system prompt you to enter the password
Method 2: Use mysqladmin
mysqladmin -u root password "newpass"
If root has already set a password, use the following method
mysqladmin -u root password oldpass "newpass"
Method 3: Use UPDATE directly Edit user table
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
When you lose the root password, you can do this
mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
mysql> FLUSH PRIVILEGES;
Related recommendations:
Summary of using the cmd command to change the root password in MYSQL
How to change the root password sharing in Mysql5.7
The above is the detailed content of Some methods for changing root password in MySQL. For more information, please follow other related articles on the PHP Chinese website!