【MySQL 18】Docker 安装 MySQL8 .0.30
创始人
2024-04-14 20:36:08

1、查看可用的 MySQL 版本

访问 MySQL 镜像库地址:

https://hub.docker.com/_/mysql?tab=tags 。

在这里插入图片描述
在这里插入图片描述

2、拉取 MySQL 8.0.30 镜像

拉取官方的指定版本的镜像:

docker pull mysql:8.0.30
[root@localhost deploy]# docker pull mysql:8.0.30
8.0.30: Pulling from library/mysql
295ca2342728: Pull complete 
79af4312a7e0: Pull complete 
48d3d73d1704: Pull complete 
521b8724b397: Pull complete 
b8cf360b4a14: Pull complete 
0115482cc006: Pull complete 
a360b08917ea: Pull complete 
12deeb3c1323: Pull complete 
ee1dc10db1e9: Pull complete 
64be404ad29c: Pull complete 
1921fe8879a2: Pull complete 
Digest: sha256:3c1aab708f6e57fc4dccafe36baccc7219acfb4ec450f3fb6d370ea89409e906
Status: Downloaded newer image for mysql:8.0.30
docker.io/library/mysql:8.0.30

3、查看本地镜像

使用以下命令来查看是否已安装了 mysql:

docker images
[root@localhost deploy]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
mysql        8.0.30    dbaea59d1b41   7 weeks ago   449MB

在上图中可以看到我们已经安装了8.0.30版本的 mysql 镜像。

在这里插入图片描述

4、运行容器

docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.30

参数说明:

  • -p 3306:3306 :映射容器服务的 3306 端口到宿主机的 3306 端口,外部主机可以直接通过 宿主机ip:3306 访问到 MySQL 的服务。

  • MYSQL_ROOT_PASSWORD=123456:设置 MySQL 服务 root 用户的密码

[root@localhost deploy]# docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.30
aab502119678b471aa2c7cb4e0b2d5f091c65e46db0e48be76f462dccb5a1d4c

在这里插入图片描述

5、安装成功

通过 docker ps 命令查看是否安装成功:

[root@localhost deploy]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                                                  NAMES
aab502119678   mysql:8.0.30   "docker-entrypoint.s…"   5 minutes ago   Up 5 minutes   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql-test

在这里插入图片描述
可以通过 root 和密码 123456 访问 MySQL 服务。

[root@localhost deploy]# docker exec -it mysql-test /bin/bash  #进入MySQL容器
bash-4.4# 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.30 MySQL Community Server - GPLCopyright (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> 

在这里插入图片描述

相关内容

热门资讯

猫咪吃了塑料袋怎么办 猫咪误食... 你知道吗?塑料袋放久了会长猫哦!要说猫咪对塑料袋的喜爱程度完完全全可以媲美纸箱家里只要一有塑料袋的响...
demo什么意思 demo版本... 618快到了,各位的小金库大概也在准备开闸放水了吧。没有小金库的,也该向老婆撒娇卖萌服个软了,一切只...
世界上最漂亮的人 世界上最漂亮... 此前在某网上,选出了全球265万颜值姣好的女性。从这些数量庞大的女性群体中,人们投票选出了心目中最美...
苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...