docker mysql8 修改密码

docker mysql8 修改密码

设置跳过密码登录

docker exec -it mysql /bin/sh
# 注:编辑的配置文件是 docker.cnf
vi /etc/mysql/conf.d/docker.cnf
exit

重启 mysql 容器

docker restart mysql

重启 mysql 容器

旧版的命令失效了:
UPDATE user SET Password = password ( ‘a123456’ ) WHERE User = ‘root’;
正确:

UPDATE mysql.user SET authentication_string='' WHERE user='root' and host='localhost';
-- 修改密码为用不过期
ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; 
flush privileges;

错误处理

ERROR 2059 (HY000): Authentication plugin ‘caching_sha2_password’ cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory

  • 可能是未设置密码永不过期
  • 可能是linux下数据库客户端版本过低,我是在服务器A上,尝试连服务器B中docker的mysql8时出现的,但在windows中使用dataGrip连接成功。

创建用户与授权

create user  'nacos'@'%' identified by '123';
grant all on mid_nacos.* to 'nacos'@'localhost' ;
flush privileges;

解决 Operation CREATE USER failed for ‘user’@’%’ 错误

可能是用户已经存在,删除重新创建即可
查看是否存在该用户:select user from user;
删除:drop user 'user'@'%';

参考: https://www.cnblogs.com/rmxd/p/11236736.html
https://www.cnblogs.com/gjc592/p/9681093.html

你可能感兴趣的:(解决方案,工具和环境)