1查看mysql容器,并进入

docker ps -a

docker exec -it  mysql  bash

2由于mysql镜像中默认没有安装vi或vim,更新apt, apt-get update 安装vim, apt-get install vim

apt-get update

apt-get install vim

3修改配置文件:

vim /etc/mysql/conf.d/docker.cnf 
在mysql配置文件中添加:skip-grant-tables

4.退出mysql容器命令行交互后,重启数据库

docker restart mysql

5重新进入mysql容器,登录mysql

docker exec -it mysql  bash

进入数据库
mysql -u root -p

# 不用输入密码直接回车enter
Enter password:  

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中的配置文件添加的语句(一定要删除或者注释掉)

vim /etc/mysql/conf.d/docker.cnf 
# skip-grant-tables

然后就可以登录了

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐