Method: 1. Use the "SET PASSWORD FOR 'root'@'localhost'=PASSWORD('newpass');" command; 2. Use "mysqladmin -u root password oldpass "newpass"".
Mysql method to change password through cmd:
1. Initialization setting password
/etc/init.d/mysql stop cd /usr/local/mysql mysqld_safe –user=mysql –skip-grant-tables –skip-networking & mysql -u root mysql mysql > UPPATE user SET password=PASSWORD(‘newpassword’) where USER=’root’; mysql > FLUSH PRIVILEGES; mysql > quit ; /etc/init.d/mysql restart mysql -u root -p
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, use the following method
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;
2. Set the root password when you lose the root password
Method 1:
mysqld_safe –skip-grant-tables& mysql -u root mysql mysql> UPDATE user SET password=PASSWORD(“new password”) WHERE user=’root’; mysql> FLUSH PRIVILEGES;
Method 2:
1. Modify the mysql configuration file (default is /etc/my.cnf) and add a line skip-grant-tables under [mysqld]
2. After saving the configuration file, restart mysql service service mysqld restart
3. Mysql -u root -p log in to mysql, then press Enter without entering the password, and then change the password according to the above process
4. After the password has been changed, follow In process 1, delete the line in the configuration file and then restart the mysql service
Related recommendations: "mysql tutorial"
The above is the detailed content of How to change mysql password through cmd?. For more information, please follow other related articles on the PHP Chinese website!