docker mysql 简书_docker安装mysql8.0

docker安装mysql8.0

1、查看可用的 MySQL 版本

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

514f63572447

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

[root@web1 ~]# docker search mysql

514f63572447

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

514f63572447

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

514f63572447

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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值