admin管理员组文章数量:1289878
docker容器中的mysql忘记密码怎么办?
1.查看mysql在docker中运行的containerID
docker ps
// 此处amber这里获取的containerID为:eb540a56a527
2.进入正在运行的mysql容器并以命令行交互:
docker exec -it eb /bin/bash
3.用vim编辑mysql配置文件(由于mysql镜像中默认没有安装vi或vim,更新apt, apt-get update 安装vim, apt-get install vim)
root@eb540a56a527:/# vim /etc/mysql/conf.d/dockerf
在mysql配置文件中添加:skip-grant-tables
4.退出mysql容器命令行交互后,重启数据库
docker restart eb540a56a527
5.重新进入mysql容器,登录mysql
docker exec -it eb /bin/bash
root@eb540a56a527:/# mysql -u root -p
Enter password: # 不用输入密码直接回车enter
mysql> use mysql;
update user set authentication_string='' where user="root";
# 如果需要给root用户设置密码
update user set plugin='mysql_native_password' where user='root'; #更改加密方式
alter user 'root'@'localhost' IDENTIFIED BY '123456';#设置密码
FLUSH PRIVILEGES;
# 退出数据库
mysql> exit
6.注释或删除刚才在mysql中的配置文件添加的语句
root@eb540a56a527:/# vim /etc/mysql/conf.d/dockerf
# skip-grant-tables
7.在docker中重启mysql数据库
docker restart eb
8.重新进入mysql容器,使用新密码登录mysql即可
docker exec -it eb /bin/bash
root@eb540a56a527:/# mysql -u root -p
Enter password: # 输入新密码 123456
版权声明:本文标题:docker容器中的mysql忘记密码怎么办? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1737970932a2042963.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论