Home >Database >Mysql Tutorial >Introduction to various methods of changing root password in mysql
There are many situations to modify the root password, the details are as follows:
Before the root password is not set:
SET PASSWORD command Method:
mysql -u root mysql>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('你要设置的密码');
mysqladmin command method: (Related video tutorial recommendation: mysql video tutorial)
mysqladmin -u root password "你要设置的密码"
UPDATE method to directly edit the user table:
mysql -u root mysql> USE mysql; mysql> UPDATE user SET Password = PASSWORD('你要设置的密码') WHERE user = 'root'; mysql> FLUSH PRIVILEGES;
After setting root:
Mysqladmin method:
mysqladmin -u root password oldpass "你要设置的新密码"
Set the root password, but forgot:
mysqld_safe --skip-grant-tables&mysql -u root mysql mysql> UPDATE user SET password = PASSWORD("你要设置的新密码") WHERE user = 'root' ; mysql> FLUSH PRIVILEGES;
Related article tutorials Recommended: mysql tutorial
The above is the detailed content of Introduction to various methods of changing root password in mysql. For more information, please follow other related articles on the PHP Chinese website!