How to quickly start a MySQL test using Docker on a Mac _docker

Source: Internet
Author: User
Tags mysql version reserved mysql command line percona percona server docker for mac docker ps docker run

This article mainly discusses the method of using Docker to quickly start a MySQL test, including the MAC environment. Let's have a look!

There has been a lot of discussion about Docker in the industry these days, and the ecosystem is developing very quickly, however, it is easy to find mature technology from simple "getting Started" or "guiding" articles, but Docker is not. I tried Docker on a Mac, but Mac is definitely a second-class citizen of the Docker world. When I read about using the new Docker beta "Docker for Mac Beta and MySQL" on a Mac on a Giuseppe blog, I decided to try it myself. These steps apply to the Mac (Windows also possible) and to the Linux environment (GA version, Docker 1.11.1).

First, register the new Docker beta program on the Mac, and then get the download code from the Docker. This process takes me a day, but the full version should be released soon. After the installation is complete, I need to set some Docker containers for the common MySQL version, and the sandbox will be available. The method is as follows:

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

Some experience Summary:

I created a network called "Test" for my container to share, essentially a proprietary private network between containers. I like this because the ports on the connection are listening on multiple containers, and you do not have to set the host operating system port.
I'm going to launch Oracle's official MySQL Docker container as a mirror of MySQL 5.7 in the bind to the test network.

I used the Mysql/shell mirror (from Oracle) to initialize the MYSQLX plugin on the MySQL 5.7 server. Note that I did not enter the password because I did not create a server (not secure, but it is a sandbox).
This inside shell uses a temporary container that is removed after it is run, so it does not break the Docker ps-a output.

So now I want to be able to access the container using the standard MySQL command line or a new MySQL shell. Make it look clean, so I added some bash aliases:

Alias Mysqlsh= ' Docker run-it--rm--net=test Mysql/shell '
alias mysql= ' Docker run-it--rm-e Ord=yes--net=test--entrypoint= "MySQL" mysql/mysql-server:5.7 '

After that, I can call them directly and connect my MySQL 5.7 mirror with the normal command-line options, just like using a native MySQL CLI binary. To use the MySQL CLI from the MySQL 5.7 Mirror:

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), 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark to Oracle Corporation and/or its
affiliates. The other names may is 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)

Using the MySQL Shell:

jayj@~ [527]$ mysqlsh-h mysql57-u root--session-type=node
Creating a node session to root@mysql57:33060
Enter p Assword:
No Default schema selected.
Welcome to the MySQL Shell 1.0.3 Development Preview
Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark to Oracle Corporation and/or its
affiliates. The other names may is trademarks of their respective
owners.
Type ' help ', ' h ' or '? '.
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>

Now, if for some thing want to run check MySQL 5.5, you can do this:

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 D:already exists 646f220a8b5d:pull complete ed65e4fea7ed:pull complete D34b408b18dd:pull complete digest:sha256:12f0b 7025d1dc0e7b40fc6c2172106cdf73b8832f2f910ad36d65228d9e4c433 status:downloaded newer image for Mysql/mysql-server : 5.5 6691dd9d42c73f53baf2968bcca92b7f4d26f54bb01d967be475193305affd4f jayj@~ [531]$ mysql-h mysql55 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), 2016, Oracle and/or its affiliates.
All rights reserved. Oracle is a registered trademark to Oracle Corporation and/or its affiliates.
The other names may is 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) or, Percona server:jayj@~ [534]$ Docker run--name=ps57--net=test-e L_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 4c 6755120a98:pull Complete 10eab0da5972:pull Complete d5159a6502a4:pull complete E595a1a01d00:pull complete DIGEST:SHA2 56: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), 2016, Oracle and/or its affiliates.
All rights reserved. Oracle is a registered trademark to Oracle Corporation and/or its affiliates.
The other names may is trademarks of their respective owners. Type ' help, ' or ' h ' for help.
Type ' C ' to clear the current input statement. Mysql>

So, it's all good, once the mirror is cached locally, adjusting the new container up and down can be painless and fast. All of this work is separated from my operating system workstation. There may be other things you can do with this setting, but no methods have been found (such as loading data files, running code to connect to these containers, etc.), but I will resolve them in the future.

The above is a small set to introduce the Mac on the use of Docker fast start MySQL test method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.