使用的`docker`安装`MySQL`,版本`8.0.12`
docker
的MySQL
容器:使用命令
docker exec -it mysql /bin/bash
MySQL
里面:root@1f88cc6f4013:/# mysql -u root -p Enter password:
mysql> select host,user,authentication_string from mysql.user;
host: 允许用户登录的ip‘位置'%表示可以远程;
user:当前数据库的用户名;
authentication_string: 用户密码(后面有提到此字段);
重点
use mysql; update user set authentication_string='' where user='root';
ALTER user 'root'@'localhost' IDENTIFIED BY '123456'; ALTER user 'root'@'%' IDENTIFIED BY '123456'
修改成功,退出重启容器,重新连接就可以了
PS:MySQL8.0
以后使用的秘钥插件是caching_sha2_password
,以前使用的都是mysql_native_password
,所以有可能出现Navicat
链接失败的错误,可以使用如下命令:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码'; FLUSH PRIVILEGES;