MySQL 部署 - Docker Compose
本文采用 docker-compose 方式,一键部署单机 MySQL 服务
# 部署
下面是 docker-compose 的配置文件 docker-compose-mysql57-single.yml
version: '3.9'
services:
mysql:
# 基于 5.7, 其他版本参考 https://registry.hub.docker.com/_/mysql
image: mysql:5.7.43
restart: always
container_name: mysql
# 更多环境变量 https://dev.mysql.com/doc/refman/5.7/en/environment-variables.html
environment:
# 设置 root 账户密码
MYSQL_ROOT_PASSWORD: passward@123
TZ: Asia/Shanghai
# 端口映射
ports:
- '3308:3306'
volumes:
- '/root/docker-compose/mysql/data:/var/lib/mysql'
- '/root/docker-compose/mysql/config/my.cnf:/etc/mysql/my.cnf'
# mysql 的一些配置
command:
--max_connections=1000
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--default-authentication-plugin=mysql_native_password
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
启动
docker-compose -f docker-compose-mysql57-single.yml up -d
1
执行后输出的日志内容如下
[root@bulk mysql57]# docker-compose -f docker-compose-mysql57-single.yml up -d
Creating network "mysql57_default" with the default driver
Pulling mysql (mysql:5.7.43)...
5.7.43: Pulling from library/mysql
70e9ff4420fb: Pull complete
7ca4383b183f: Pull complete
3e282e7651b1: Pull complete
1ffa0e0ca707: Pull complete
6eb790cf6382: Pull complete
b4b277ff2929: Pull complete
692fe4469429: Pull complete
c0d447d97bbd: Pull complete
99ee594517ba: Pull complete
a9ae52de4d77: Pull complete
66cc05a182b5: Pull complete
Digest: sha256:2c23f254c6b9444ecda9ba36051a9800e8934a2f5828ecc8730531db8142af83
Status: Downloaded newer image for mysql:5.7.43
Creating mysql ... done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 验证
进入到容器内部
docker exec -it <mysql-container-id> mysql -p
1
之后会让你输入密码,输入在配置文件中配置的密码即可(如果你按照文档走的话,密码是 passward@123
)
[root@bulk mysql57]# docker exec -it ffe14 mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.43 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, 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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
查看数据库
SHOW DATABASES;
1
效果如下
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
也可以尝试使用链接工具链接,root账号,注意开放端口。
如此你就安装成功了!
上次更新: 2023/09/22, 15:55:31