docker安装mysql8.0

docker安装mysql8.0

1、查看可用的 MySQL 版本

访问 MySQL 镜像库地址:https://hub.docker.com/_/mysql?tab=tags 。

可以通过 Sort by 查看其他版本的 MySQL,默认是最新版本 mysql:latest 。

此外,我们还可以用 docker search mysql 命令来查看可用版本:

[root@web1 ~]# docker search mysql

2、拉取 MySQL 镜像

这里我们拉取官方的最新版本的镜像:

[root@web1 ~]# docker pull mysql:latest

latest: Pulling from library/mysql

852e50cd189d: Already exists

29969ddb0ffb: Pull complete

a43f41a44c48: Pull complete

5cdd802543a3: Pull complete

b79b040de953: Pull complete

938c64119969: Pull complete

7689ec51a0d9: Pull complete

a880ba7c411f: Pull complete

984f656ec6ca: Pull complete

9f497bce458a: Pull complete

b9940f97694b: Pull complete

2f069358dc96: Pull complete

Digest: sha256:4bb2e81a40e9d0d59bd8e3dc2ba5e1f2197696f6de39a91e90798dd27299b093

Status: Downloaded newer image for mysql:latest

docker.io/library/mysql:latest

3、查看本地镜像

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

$ docker images


4、运行容器

安装完成后,我们可以使用以下命令来运行 mysql 容器:

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

参数说明:

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

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

[root@web1 ~]# docker run -itd  --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql

00399bebf7fcb57bb76f3adf99ba9b6b4c35cf1a46f2a60a9f2362c5feb23726

5、安装成功

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

[root@web1 ~]# docker ps -l

5.1进入容器内部

[root@web1 ~]# docker exec -it mysql-test /bin/bash

本机可以通过 root 和密码 123456 访问 MySQL 服务。

5.2登录mysql服务

root@00399bebf7fc:/# mysql -h localhost -uroot -p123456

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 8.0.22 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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、安装docker 2、拉取MySQL的镜像 运行完以上命令之后,镜像就已经下载下来了 3、查看镜像情况 可以看...
    牧瀬紅莉栖_阅读 944评论 0 1
  • 在阿里云弄了台优惠版的服务器,打算用docker安装MySQL8.0机器是Ubuntu16.04的操作系统 1、安...
    噢是LJY阅读 16,505评论 2 6
  • 记一次docker安装mysql -p 3306:3306:将容器的3306端口映射到主机的3306端口-v /h...
    mcdull_t阅读 1,043评论 0 1
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 7,583评论 16 22
  • 今天感恩节哎,感谢一直在我身边的亲朋好友。感恩相遇!感恩不离不弃。 中午开了第一次的党会,身份的转变要...
    迷月闪星情阅读 10,620评论 0 11