The difference between mysql5.7 and mysql8 to modify the root password

Project scenario:

        mysql modify the user's account password.

Pay attention to avoid pits:

        In MySQL, the SQL statement to modify the root user password is SET PASSWORD.

        In MySQL 5.7 , the password of the root user can be modified by the following statement:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');

        In versions after MySQL 8.0 , due to the new user authentication plug-in and the change of the encryption method, the statement for modifying the root user password is different, and one of the following two methods can be used:

        A. Use  ALTER USER the statement:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

        B. Use  SET PASSWORD the statement, but you need to specify the encryption method as  mysql_native_password:

SET PASSWORD FOR 'root'@'localhost' = 'new_password' USING mysql_native_password;

     Note that here 'new_password'refers to the new password and needs to be replaced with the actual password.


Guess you like

Origin blog.csdn.net/qq_33415990/article/details/129981468