当前位置:网站首页>docker 部署mysql8.0
docker 部署mysql8.0
2022-07-01 18:38:00 【51CTO】
这个平台第一篇博客记录下,哈哈哈哈
有一说一,这些文档还挺不错的
拉去mysql镜像
[[email protected] ~]# docker pull mysql:8.0
8.0.27: Pulling from library/mysql
72a69066d2fe: Pulling fs layer
93619dbc5b36: Pulling fs layer
99da31dd6142: Pulling fs layer
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
688ba7d5c01a: Pull complete
00e060b6d11d: Pull complete
1c04857f594f: Pull complete
4d7cfa90e6ea: Pull complete
e0431212d27d: Pull complete
Digest: sha256:e9027fe4d91c0153429607251656806cc784e91493271037f7738bd5b8e7709
Status: Downloaded newer image for mysql:8.0
docker.io/library/mysql:8.0
创建映射挂载卷目录
[[email protected] mysql8]# pwd
/opt/mysql8
[[email protected] mysql8]# mkdir conf
[[email protected] mysql8]# mkdir logs
[[email protected] mysql8]# mkdir data

在conf目录新建my.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
# Custom config should go here
!includedir /etc/mysql/conf.d/
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
运行容器
docker run --restart=always \
-v /opt/mysql8/conf/my.cnf:/etc/mysql/my.cnf \
-v /opt/mysql8/logs:/logs \
-v /opt/mysql8/data/:/var/lib/mysql \
-p 3310:3306 \
--name mysql8 \
-d mysql:8.0 \
-e MYSQL_ROOT_PASSWORD='123123' \
--privileged=true \
--character-set-server=utf8mb4
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
参数解析
参数 | 含义 |
--restart=always | 当 Docker 重启时,容器自动启动 |
--name | 起别名 |
-p 3306:3306 | 映射端口 |
-v | 目录挂载 |
d mysql:8.0 | 指定运行版本 |
-e MYSQL_ROOT_PASSWORD=‘密码’ | 设置root用户密码 |
--privileged=true | 赋予系统root权限 |
--character-set-server=utf8mb4 | 设置字符集为utf8mb4 |
操作步骤
(一)、新建文件
[[email protected] mysql8]
# pwd
/opt/mysql8
[[email protected] mysql8]
# mkdir conf
[[email protected] mysql8]
# mkdir logs
[[email protected] mysql8]
# mkdir data
- 1.
- 2.
- 3.
- 4.
- 5.
(二)、拉取mysql8.0镜像
[[email protected] ~]
# docker pull mysql:8.0
8.0: Pulling from library/mysql
72a69066d2fe: Pulling fs layer
93619dbc5b36: Pulling fs layer
99da31dd6142: Pulling fs layer
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
688ba7d5c01a: Pull complete
00e060b6d11d: Pull complete
1c04857f594f: Pull complete
4d7cfa90e6ea: Pull complete
e0431212d27d: Pull complete
Digest: sha256:e9027fe4d91c0153429607251656806cc784e91493271037f7738bd5b8e7709
Status: Downloaded newer image
for mysql:8.0
docker.io/library/mysql:8.0
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
(三)、在conf目录新建my.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
# Custom config should go here
!includedir /etc/mysql/conf.d/
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
(四)、在conf目录新建my.cnf
docker run --restart=always -d \
-v /opt/mysql8/conf/my.cnf:/etc/mysql/my.cnf \
-v /opt/mysql8/logs:/logs \
-v /opt/mysql8/data:/var/lib/mysql \
-p 3310:3306 \
--name mysql8 \
-e MYSQL_ROOT_PASSWORD='123123' \
--privileged=true --restart unless-stopped mysql:8.0 \
--character-set-server=utf8mb4
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
(五)、验证mysql版本
获取容器名
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8082f1 mysql:8.0 " t.s…" ago hours 33060/tcp 06>3306/tcp mysql8
- 1.
- 2.
- 3.

进入容器内部查看mysql版本

输入mysql -uroot -p ,输入部署的密码即可,8.0.29这是最新的8版本
[email protected]:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.29 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>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
修改密码
使用select user,plugin from user where user='root'; 查看加密方式
上面的语句执行后,服务器记得开启外网端口,使用数据库软件进行连接
使用数据库软件进行连接

边栏推荐
- 6款红黄黑榜摄像头评测:谁最安全?谁画质好?从此让你不再踩雷
- Unity learning fourth week
- 每周推荐短视频:警惕“现象”与“问题”相互混淆
- 用WPF写一款开源方便、快捷的数据库文档查询、生成工具
- 为什么独立站卖家都开始做社交媒体营销?原来客户转化率能提高这么多!
- 如何在自有APP内实现小程序实现连麦直播
- Reading notes series "modern methods of C language programming" -- Chapter 2
- [CF1476F]Lanterns
- Mise en place d'une plate - forme générale de surveillance et d'alarme, quelles sont les conceptions nécessaires dans l'architecture?
- Implement a Prometheus exporter
猜你喜欢

After studying 11 kinds of real-time chat software, I found that they all have these functions

Facebook聊单,SaleSmartly有妙招!

Search 2D matrix 2

AI 训练速度突破摩尔定律;宋舒然团队获得RSS 2022最佳论文奖

每周推荐短视频:警惕“现象”与“问题”相互混淆

About enterprise middle office planning and it architecture microservice transformation

Unity learning fourth week

Using OpenSSL encryption to rebound shell traffic

LiveData postValue会“丢”数据

用GSConv+Slim Neck改进Yolov5,将性能提升到极致!
随机推荐
Mysql database design
Leetcode203 移除链表元素
R language uses the transmute function of dplyr package to calculate the moving window mean value of the specified data column in dataframe data, and uses ggplot2 package to visualize the line graph b
Reading notes series "modern methods of C language programming" -- Chapter 2
Go Technology Daily (2022-02-14) - go language slice interview real questions 8 consecutive questions
Introduction to easyclick database
R language ggplot2 visualization: visualize the line graph and add customized Y-axis label information to the line graph using the labels function
Financial judgment questions
R language uses follow up of epidisplay package Plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses n.of The lines parameter specifies the num
R language ggplot2 visualization: gganimate creates a dynamic histogram animation (GIF), and displays the histogram and enter step by step along a given dimension in the animation_ Growth function and
How to change guns for 2D characters
Relational database management system of easyclick
Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
C language learning notes: type definition typedef and declaration external CSDN creation punch in
R language ggplot2 visualization: gganimate package transition_ Time function to create dynamic scatter animation (GIF), shadow_ The wake function configures the gradient falloff tailing effect of the
Localization through custom services in the shuttle application
Lumiprobe 生物分子定量丨QuDye 蛋白定量试剂盒
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
NSI packaging script add file details
Thread forced join, thread forced join application scenarios