docker exec -it 容器ID /bin/bash
第二步连接mysql
mysql -uroot -p
输入密码后,登录mysql终端
第三步修改密码
SET PASSWORD FOR 'root' = PASSWORD('设置的密码');
第四步重启
重启mysql容器即可
docker restart 容器ID
补充:docker 启动mysql容器启动初始化默认密码问题 -e MYSQL_ROOT_PASSWORD
docker run -p 3308:3308 --name=mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6
Initializing database
[root@localhost mugutu]# docker run -p 3308:3308 --name=mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6
Initializing database
2018-12-02 13:42:53 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-02 13:42:53 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-12-02 13:42:53 0 [Note] /usr/sbin/mysqld (mysqld 5.6.41) starting as process 32 ...
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。如有错误或未考虑完全的地方,望不吝赐教。