侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Mac上使用Docker如何快速启动MySQL测试

Docker  /  管理员 发布于 7年前   207

本文主要讨论使用Docker快速启动 MySQL 测试的方法,包括Mac环境。一起看看吧!

近来业界有很多对Docker的讨论,其生态系统发展得很快,然而,从简单的“入门”或“引导”类的文章中能容易地找到成熟的技术,但Docker不然。我在Mac上试玩过Docker,但Mac绝对是Docker界的二等公民。当我在Giuseppe的博客上看到关于在Mac上使用新Docker beta《Docker for Mac beta and MySQL》一文时,决定自己来尝试下。这些步骤适用于Mac(Windows也可能),亦能适配Linux环境(GA版本,Docker 1.11.1)。

首先,在Mac上注册新的Docker测试版程序,接着从Docker中获得下载代码。此过程我耗时一天,但应该不久就会发布完整版。安装完成后,我需要为常见的MySQL版本设置一些Docker容器,沙箱也就有了。方法如下:

jayj@~ [510]$ docker network create test90005b3ffa9fef1f817ee4965e794a567404c9a8d5bf07320514e7d848d59ff9jayj@~ [511]$ docker run --name=mysql57 --net=test -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql/mysql-server:5.76c80fa89610dbd5418ba474ad7d5451cd061f80a8a72ff2e718341827a08144bjayj@~ [512]$ docker run -it --rm --net=test -e MYSQL_HOST=mysql57 mysql/shell initCreating a Classic Session to root@mysql57:3306Enter password:No default schema selected.enableXProtocol: Installing plugin mysqlx...enableXProtocol: done

一些经验总结:

我为我的容器创建了一个名为“测试”的网络以共享,本质是容器之间一个专用的私有网络。我喜欢这个是因为在相关的端口是监听多个容器,也不必设置主机操作系统的端口。
我将Oracle的官方MySQL Docker容器启动一个MySQL 5.7的镜像,在绑定到该测试网络。

我使用了MySQL /shell镜像(来自Oracle)来初始化MySQL 5.7服务器上的mysqlx插件。需要注意的是,我并没有输入密码,因为我没有创建一个服务器(不安全,但它是一个沙箱)。
这个里面的Shell使用了运行后删除的临时容器,所以并不会破坏Docker ps-a输出。

所以,现在我希望能够使用标准的MySQL命令行或新的MySQL shell来访问这个容器。让它看起来很干净,因此我添加了一些bash别名:

alias mysqlsh='docker run -it --rm --net=test mysql/shell'alias mysql='docker run -it --rm -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --net=test --entrypoint="mysql" mysql/mysql-server:5.7'

这些以后,我可以直接调用他们并通过正常的命令行选项来连接我的MySQL 5.7镜像,就像使用的是一个原生的MySQL CLI binary。从MySQL 5.7镜像中使用MySQL CLI:

jayj@~ [524]$ mysql -h mysql57Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 4Server version: 5.7.12 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.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> show schemas;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.01 sec)

使用MySQL shell:

jayj@~ [527]$ mysqlsh -h mysql57 -u root --session-type=nodeCreating a Node Session to root@mysql57:33060Enter password:No default schema selected.Welcome to MySQL Shell 1.0.3 Development PreviewCopyright (c) 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help', 'h' or '?' for help.Currently in JavaScript mode. Use sql to switch to SQL mode and execute queries.mysql-js> sqlSwitching to SQL mode... Commands end with ;mysql-sql> show schemas;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.00 sec)mysql-sql>

现在,如果为了一些事情想要运行检查MySQL 5.5,可以这样做:

jayj@~ [530]$ docker run --name=mysql55 --net=test -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql/mysql-server:5.5Unable to find image 'mysql/mysql-server:5.5' locally5.5: Pulling from mysql/mysql-servera3ed95caeb02: Already existsffe36b360c6d: Already exists646f220a8b5d: Pull completeed65e4fea7ed: Pull completed34b408b18dd: Pull completeDigest: sha256:12f0b7025d1dc0e7b40fc6c2172106cdf73b8832f2f910ad36d65228d9e4c433Status: Downloaded newer image for mysql/mysql-server:5.56691dd9d42c73f53baf2968bcca92b7f4d26f54bb01d967be475193305affd4fjayj@~ [531]$ mysql -h mysql55Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 1Server version: 5.5.49 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.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> show schemas;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema |+--------------------+3 rows in set (0.00 sec)或者,Percona Server:jayj@~ [534]$ docker run --name=ps57 --net=test -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d percona/percona-server:5.7Unable to find image 'percona/percona-server:5.7' locally5.7: Pulling from percona/percona-servera3ed95caeb02: Pull completea07226856d92: Pull completeeee62d87a612: Pull complete4c6755120a98: Pull complete10eab0da5972: Pull completed5159a6502a4: Pull completee595a1a01d00: Pull completeDigest: sha256:d57f0ce736f5403b1714ff8d1d6b91d5a7ee7271f30222c2bc2c5cad4b4e6950Status: Downloaded newer image for percona/percona-server:5.79db503852747bc1603ab59455124663e8cedf708ac6d992cff9b43e2fbebd167jayj@~ [537]$ mysql -h ps57Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 2Server version: 5.7.10-3 Percona Server (GPL), Release 3, Revision 63dafafCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.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>

所以,这一切都很好,一旦镜像被本地缓存,上下调整新的容器可以实现无痛和快速。所有这一切的工作都是与我的操作系统工作站分离的。可能还有其他事情可以使用这种设置,但还没找到方法(如加载数据文件、运行代码来连接这些容器等),但将来我会解决。

以上所述是小编给大家介绍的Mac上使用Docker快速启动MySQL测试的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对站的支持!


  • 上一条:
    pipework docker无法使用ip netns命令解决办法
    下一条:
    利用docker搭建LAMP运行环境教程详解
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在docker环境中实现Laravel项目执行定时任务和消息队列流程步骤(0个评论)
    • 在MacBook下laravel项目多php版本docker开发环境配置方案(0个评论)
    • 在docker环境中部署docker部署elk架构流程步骤(1个评论)
    • docker compose跟Dockerfile的区别浅析(0个评论)
    • Ubuntu 22.04系统中安装podman流程步骤(1个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2017-11
    • 2020-06
    • 2021-05
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-11
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2024-03
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客