本文主要讨论使用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 test

90005b3ffa9fef1f817ee4965e794a567404c9a8d5bf07320514e7d848d59ff9

jayj@~ [511]$ docker run --name=mysql57 --net=test -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql/mysql-server:5.7

6c80fa89610dbd5418ba474ad7d5451cd061f80a8a72ff2e718341827a08144b

jayj@~ [512]$ docker run -it --rm --net=test -e MYSQL_HOST=mysql57 mysql/shell init

Creating a Classic Session to root@mysql57:3306

Enter 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 mysql57

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

Your MySQL connection id is 4

Server 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 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> 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=node

Creating a Node Session to root@mysql57:33060

Enter password:

No default schema selected.

Welcome to MySQL Shell 1.0.3 Development Preview

Copyright (c) 2016, 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', 'h' or '?' for help.

Currently in JavaScript mode. Use sql to switch to SQL mode and execute queries.

mysql-js> sql

Switching 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.5

Unable to find image 'mysql/mysql-server:5.5' locally

5.5: Pulling from mysql/mysql-server

a3ed95caeb02: Already exists

ffe36b360c6d: Already exists

646f220a8b5d: Pull complete

ed65e4fea7ed: Pull complete

d34b408b18dd: Pull complete

Digest: sha256:12f0b7025d1dc0e7b40fc6c2172106cdf73b8832f2f910ad36d65228d9e4c433

Status: Downloaded newer image for mysql/mysql-server:5.5

6691dd9d42c73f53baf2968bcca92b7f4d26f54bb01d967be475193305affd4f

jayj@~ [531]$ mysql -h mysql55

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

Your MySQL connection id is 1

Server 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 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> 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.7

Unable to find image 'percona/percona-server:5.7' locally

5.7: Pulling from percona/percona-server

a3ed95caeb02: Pull complete

a07226856d92: Pull complete

eee62d87a612: Pull complete

4c6755120a98: Pull complete

10eab0da5972: Pull complete

d5159a6502a4: Pull complete

e595a1a01d00: Pull complete

Digest: sha256:d57f0ce736f5403b1714ff8d1d6b91d5a7ee7271f30222c2bc2c5cad4b4e6950

Status: Downloaded newer image for percona/percona-server:5.7

9db503852747bc1603ab59455124663e8cedf708ac6d992cff9b43e2fbebd167

jayj@~ [537]$ mysql -h ps57

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

Your MySQL connection id is 2

Server version: 5.7.10-3 Percona Server (GPL), Release 3, Revision 63dafaf

Copyright (c) 2000, 2016, 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>

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

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

mac mysql docker_Mac上使用Docker如何快速启动MySQL测试相关推荐

  1. docker 测试mysql_Mac上使用Docker快速启动MySQL测试

    本文主要讨论如何使用Docker快速启动 MySQL 测试,包括Mac环境. 近来业界有很多对Docker的讨论,其生态系统发展得很快,然而,从简单的"入门"或"引导&q ...

  2. Docker中快速安装Mysql

    1.下载 mysql $ docker pull mysql 默认安装最新版本的mysql(注意可能不是稳定版本)$ docker pull mysql:版本号 安装指定版本的mysql ## 此处以 ...

  3. mysql导入数据表越来越慢,快速解决mysql导数据时,格式不对、导入慢、丢数据的问题...

    快速解决mysql导数据时,格式不对.导入慢.丢数据的问题 如果希望一劳永逸的解决慢的问题,不妨把你的mysql升级到mysql8.0吧,mysql8.0默认的字符集已经从latin1改为utf8mb ...

  4. mysql sail_再谈docker搭建nginx+php+mysql开发环境 | Sail

    写在前面 前几天我写了一篇博客docker搭建nginx+php+mysql开发环境.当时主要是参考一片博文搭建记录的. 可是这样搭建出来是有一些问题的,具体的原因我还没找出.当然那篇文章还是有一些参 ...

  5. docker安装及启动mysql服务

    目录 1.docker安装mysql 2.连接数据库 1.docker安装mysql 前提:确保自己的服务器已经安装好了docker (1)输入命令,查看docker, docker info 或 d ...

  6. 修改mysql数据库名方法_安全快速修改Mysql数据库名的5种方法

    1. RENAME DATABASE db_name TO new_db_name 这个..这个语法在mysql 5.1.7中被添加进来,到了5.1.23又去掉了. 据说有可能丢失数据.还是不要用的好 ...

  7. Mac系统下如何使用命令行方式启动MySQL

    首先,先去官网下载MySQL,选择Mac版本的DMG格式的文件. 官网地址为:dev.mysql.com/downloads/mysql/5.7.html 然后下载后,直接双击对应的dmg格式的文件进 ...

  8. mysql root用户可以同时几个人连接_重学MySQL系列(四):10分钟快速掌握MySQL用户与权限管理

    在这篇文章中,我们来聊聊怎么管理MySQL的用户及如何为不同用户分配不同的管理权限,其实,在日常使用MySQL的过程中,这部分的工作是由DBA(数据管理员)来完成的. 而我们作为一般的开发人员,只要拿 ...

  9. linux mysql批量导入数据,linux怎么快速导入Mysql数据库与导出

    linux怎么快速导入Mysql数据库与导出 Era • 2013 年 05 月 19 日 搞了一个vps,最近在学习linux,就记录一些学习的心得吧. 使用phpadmin导入.卖出数据库比较慢不 ...

最新文章

  1. Unity 2021创建2D休闲点击器游戏视频教程
  2. java一个点围着另一个点转_Java:按指定的度数值旋转另一个
  3. helm部署minio
  4. 基本的SQL-SELECT语句
  5. 信息技术计算机网络课堂实录,信息技术教案:计算机网络简介
  6. Codeforces Round #460 (Div. 2): E. Congruence Equation(枚举)
  7. 2021龙小丽高考成绩查询,学霸高考672分,家长强令复读考清华,分数出来全家人失望...
  8. 【第24章】工控安全需求分析与安全保护工程(软考:信息安全工程师)-- 学习笔记
  9. EDA实验:数字频率计(FREQ)设计(VHDL)
  10. 光猫DNS服务器未响应,有光纤猫了还要猫吗?
  11. 使用较广泛的安全测试工具有哪些?
  12. ACM-Week 2
  13. 外汇天眼:英国研究人员与南非合作应对气候变化
  14. 解决打包过程中出现 ModuleNotFoundError: No module named ‘pydicom.encoders.gdcm‘ 报错的方法
  15. English Learning - L3 综合练习 1 VOA-Color 2023.04.26 周三
  16. [转](9)跨段跳转,短调用和长调用堆栈图
  17. IDC具体是干什么的?
  18. 微信公众平台-openid获取
  19. npm - 换淘宝源
  20. 中小企业在管理中常见的几大问题

热门文章

  1. (商品评价页)商品星级评分html+css+js
  2. 苹果发布AirPods 3,TWS真无线蓝牙耳机市场活力依旧
  3. 如何查找某一个数据?
  4. 【前端学习-16】【day06】WebAPI编程/动画函数封装/回调函数/轮播图/自动播放/节流阀/返回顶部/筋斗云/触屏事件/触屏事件对象/
  5. js练习:筋斗云案例练习
  6. 使用华为手机怎么从网上打印资料?
  7. hdu4322 candy 费用流
  8. eureka服务返回的数据是xml格式
  9. 4点策略教你如何做好社群营销
  10. 数据分析师之所需要了解的产品系列知识(二)——如何测试产品健康