【MySQL 18】Docker 安装 MySQL8 .0.30
创始人
2024-03-02 14:40:45
0

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> 

在这里插入图片描述

相关内容

热门资讯

前端-session、jwt 目录:   (1)session (2&#x...
linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
关于测试,我发现了哪些新大陆 关于测试 平常也只是听说过一些关于测试的术语,但并没有使用过测试工具。偶然看到编程老师...
前缀和与对数器与二分法 1. 前缀和 假设有一个数组,我们想大量频繁的去访问L到R这个区间的和,...
nodejs:本地安装nvm实... 一、背景-使用不同版本node的原因 vue3+ts、nuxt3版本,node...
JAVA集合知识整理 Java集合知识整理 HashMap相关 HashMap的底层数据结构:jdk1.8之...
无刷直流电机介绍及单片机控制实... 无刷直流电机介绍及单片机控制实例前言基本概念优势与劣势使用寿命基本结构使用单片机控制实例电子调速器&...
fwdiary(2) dp2 1.传纸条  AcWing 275. 传纸条 - AcWing 走两条路,走一条最大的...
常用的DOS命令 常用的DOS命令 DOS(Disk Operating System,磁...
<C++> 类和对象(下) 1.const成员函数将const修饰的“成员函数”称之为const成员函数,cons...