docker 部署mysql8.0

网友投稿 293 2022-10-18

docker 部署mysql8.0

拉去mysql镜像

[root@rzk ~]# docker pull mysql:8.08.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

创建映射挂载卷目录

[root@rzk mysql8]# pwd /opt/mysql8[root@rzk mysql8]# mkdir conf[root@rzk mysql8]# mkdir logs[root@rzk mysql8]# mkdir data

在conf目录新建my.cnf

[mysqld]pid-file = /var/run/mysqld/mysqld.pidsocket = /var/run/mysqld/mysqld.sockdatadir = /var/lib/mysqlsecure-file-priv= NULL# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0character-set-server=utf8[client]default-character-set=utf8[mysql]default-character-set=utf8# Custom config should go here!includedir /etc/mysql/conf.d/

运行容器

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

参数解析

参数

含义

--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

操作步骤

(一)、新建文件

[root@rzk mysql8]# pwd/opt/mysql8[root@rzk mysql8]# mkdir conf[root@rzk mysql8]# mkdir logs[root@rzk mysql8]# mkdir data

(二)、拉取mysql8.0镜像

[root@rzk ~]# docker pull mysql:8.08.0: Pulling from library/mysql72a69066d2fe: 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:e9027fe4d91c0153429607251656806cc784e91493271037f7738bd5b8e7709Status: Downloaded newer image for mysql:8.0docker.io/library/mysql:8.0

(三)、在conf目录新建my.cnf

[mysqld]pid-file = /var/run/mysqld/mysqld.pidsocket = /var/run/mysqld/mysqld.sockdatadir = /var/lib/mysqlsecure-file-priv= NULL# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0character-set-server=utf8[client]default-character-set=utf8[mysql]default-character-set=utf8# Custom config should go here!includedir /etc/mysql/conf.d/

(四)、在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

(五)、验证mysql版本

获取容器名

[root@rzk ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8082f1 mysql:8.0 " t.s…" ago hours 33060/tcp 06>3306/tcp mysql8

进入容器内部查看mysql版本

[root@rzk ~]# docker exec -it 808 bashroot@8082f19b024b:/#

输入mysql -uroot -p ,输入部署的密码即可,8.0.29这是最新的8版本

root@8082f19b024b:/# mysql -uroot -pEnter password:

root@8082f19b024b:/# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 8Server version: 8.0.29 MySQL Community Server - GPLCopyright (c) 2000, 2022, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

修改密码

使用select user,plugin from user where user='root'; 查看加密方式

1、use mysql;2、ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';3、update user set host='%' where user='root';4、flush privileges;

上面的语句执行后,服务器记得开启外网端口,使用数据库软件进行连接

使用数据库软件进行连接

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:虚拟机挂起后再恢复后Docker部署的应用无法连接
下一篇:SpringBoot2零基础到精通之配置文件与web开发
相关文章

 发表评论

暂时没有评论,来抢沙发吧~