rpm -qa | grep docker
(1)、检查防火墙状态
systemctl status firewalld.service
(2)、临时关闭防火墙
systemctl stop firewalld.service
(3)、永久关闭防火墙
systemctl disable firewalld.service
yum install -y yum-utils devi ce-mapper-pers istent-data 1vm2 --ski p- broken
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce
docker -v
systemctl start docker
链接: 参考文章.
docker pull mysql:8.0.28
docker images mysql:8.0.28
mkdir -p /data/docker/mysql8/conf #配置文件目录
mkdir -p /data/docker/mysql8/data #数据目录
mkdir -p /data/docker/mysql8/logs #日志目录
(1)、在/data/docker/mysql8/conf目录下创建my.cnf文件
touch /data/docker/mysql8/conf/my.cnf
(2)、编辑my.cnf并配置
vi /data/docker/mysql8/conf/my.cnf
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
port=3308
init_connect='SET collation_connection = utf8mb4_general_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
skip-character-set-client-handshake
skip-name-resolve
# 最大连接数
max_connections=1000
docker run -p 3308:3308--name mysql8.0.28 -v /data/docker/mysql8/conf:/etc/mysql -v /data/docker/mysql8/data:/var/lib/mysql-files -v /data/docker/mysql8/logs:/var/log -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0.28
注意:忽略mysql8.0的大小写,不支持在my.cnf配置。需要在启动镜像时 追加 --lower-case-table-names=1 参数
(docker run -p 3308:3308--name mysql8.0.28 -v /data/docker/mysql8/conf:/etc/mysql -v /data/docker/mysql8/data:/var/lib/mysql-files -v /data/docker/mysql8/logs:/var/log -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0.28 --lower-case-table-names=1)
docker ps
密码加密方式导致无法连接(如下图)
(1)、查看容器id
docker ps
(2)、登录mysql8.0.28
docker exex -it c11319beeff3 bash
注意: c11319beeff3 表示容器的id
(3)、输入用户名和密码进入mysql
root@c11319beeff3:/# mysql -uroot -p123456
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 14
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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>
(4)、查看密码加密规则
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)
mysql>
(5)、修改密码加密规则并刷新权限使密码生效
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
(6)、查看密码加密规则是否生效
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | mysql_native_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)