Docker容器中MySQL异常,远程无法链接排查记录

一、跳过MySQL权限认证

1.1  编辑配置文件:输入命令

vi /etc/mysql/conf.d/docker.cnf

1.2  docker.cnf文件中添加skip-grant-tables跳过权限认证

[mysqld]
skip-host-cache
skip-name-resolve
skip-grant-tables

或:

mysqld -nt –skip-grant-tables

1.3 具体描述

  1. 通过exit退出docker容器
  2. 重启MySQL容器,重新进入容器内部
  3. 通过 mysql -u root -p  直接登录

1.4 查看当前密码策略

  1. 先选择数据库: use mysql;
  2. 执行命令:       select user,host from user;
  3. 如果没有%这个host值,就执行命令
  4. update user set host='%' where user='root';

  5.  

    最后执行:flush privileges; 

1.5 创建新用户和密码输入以下命令

grant usage on *.* to ‘zhihao'@'localhost' identified by ‘123456';

1.6 授权可以远程登录

grant all privileges on *.* to root@'%'identified by 'passwd';//设置可以远程访问

1.7 修改密码

update user set authentication_string=password(‘xxx’) where user=’账户名’ and host=’localhost’;

1.7 刷新权限

flush privileges;

 

 

欢迎关注作者微信公众号

 

posted @ 2022-04-23 12:25  沾青先生  阅读(503)  评论(0编辑  收藏  举报