Article Directory
Mysql5.7 is the modification method of mysql7.0
1. If you are using mysql installed in docker,
first use
[root@localhost /]# docker ps # to view the currently running container, and the id of the container will also be displayed
[root@localhost /]# docker exec -it container id /bin /bash
root@b46d2c5dcd13:/# mysql -u root -p password
mysql>update user set authentication_string = 'new password' where user = ''root'';
mysql>flush privileges;
#Exit login
mysql>exit
root@b46d2c5dcd13:/# mysql -u root -p new password
mysql> #If you can come in, it means that the modification has been successful.
Mysql5.8 is the modification method of mysql8.0
1. If you are using mysql installed in docker,
first use
[root@localhost /]# docker ps # to view the currently running container, and the id of the container will also be displayed
[root@localhost /]# docker exec -it container id /bin /bash
root@b46d2c5dcd13:/# mysql -u root -p password
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码'
;
or
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码'
;
mysql>flush privileges;
#Exit login
mysql>exit
root@b46d2c5dcd13:/# mysql -u root -p new password
mysql> #If you can come in, it means that the modification has been successful.
What should I do if I find that both the old password and the new password cannot be logged in after changing the password?
Add skip-grant-tables under [mysqld] in the my.cnf file and restart mysql. Then log in again, when prompted to enter the password, just enter to skip entering the password. Go directly to mysql >
It is found that the old error is reported when setting the password
You can first look at the current password
select user, host, authentication_string from mysql.user;
reset the password to an empty string
update mysql.user set authentication_string='' where user='root or other user name';
reset the password, Follow the way of mysql5.7 or mysql5.8.