1. 创建MYSQL8
docker run -it -d -p 3328:3306 --name docker_8_3328_mysql -e MYSQL_ROOT_PASSWORD=密码 --privileged=true --restart always -d mysql:8
2.添加防火墙端口
firewall-cmd --permanent --zone=public --add-port=3328/tcp
3.进入docker容器修改密码
docker exec -it 5160bdcd9252 bash
4.修改docker容器mysql信息
root@5160bdcd9252:/# mysql -uroot -p密码
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 8.0.20 MySQL Community Server - GPLCopyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'%' identified by '密码' password expire never;
Query OK, 0 rows affected (0.02 sec)mysql> alter user 'root'@'%' identified with mysql_native_password by '密码';
Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
来源:oschina
链接:https://my.oschina.net/jywm/blog/4308471