Quickly set up the local mysql environment

As a front-end developer, gradually contact the development of back-end (node), business needs gradually accumulated, node layer from the data aggregation layer also gradually have the need to use mysql, Redis, today share the use of docker to quickly build mysql, but also in order to self-record.

docker

First of all, a brief introduction to several basic concepts of Docker: In brief, Docker is also a cross-platform solution to ensure that the environment running on each platform is consistent. Each Docker container creates a separate, isolated environment.

Docker image: can be understood as images, from these basic images can create a default, initial Docker container.

Dockerfile: Generates containers based on dockerfile and records initialization commands during or after container creation, such as downloading dependencies and modifying configurations.

Docker Hub: Docker officially provides a remote repository to store Docker images, providing the ability to manage images (can be understood as Github)

The official start of the

  • usesearchCommand to search for all available mysql versions on the hub
╭ ─ ~ / ShopeeWorkspace/NodejsWorkspace/themis - be ‹ dev holds the ╰ ─ ➤ docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED Mysql mysql is a widely used, open-source relation... 9542 [OK] Mariadb Mariadb is a community-developed fork of MyS... 3461 [OK] mysql/mysql-server Optimized mysql Server Docker images.create... 699 [OK] centos/mysql-57-centos7 mysql 5.7 SQL Database Server 75 mysql/mysql-cluster Experimental mysql cluster Docker Images. The Cr... 69 Centurylink /mysql Image Containing mysql. Optimized to be Link... 61 [OK] deitch/mysql-backup REPLACED! Both Please use http://hub.docker.com/r... 39 [OK] tutum/mysql Base Docker Image to run a mysql database se... 35 schickling/mysql-backup-sSupports Supports periodic Backup to S3 (Supports periodic Backup... 29 [OK] LINUxserver/mysqlD-exporter A mysql container, brought to you by Linux... 25 centos/mysql-56-centos7 mysql 5.6 SQL database server 19 circleci/mysql mysql is a widely used, open-source relation...  19 databack/mysql-backup Back up mysql databases to... anywhere! 18 mysql/mysql-router Mysql router provides transparent routing be... 15 arey/mysql-client Run a MySQL client from a docker container 14 [OK] openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL V5.5 image... 6 Fradelg /mysql-cron-backup mysql /MariaDB database backup using cron tas... 6 [OK] genschsa/mysql-employees MySQL Employee Sample Database 5 [OK] devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offici... 3 ansibleplaybookbundle/mysql-apb An APBwhichDeploys RHSCL MySQL 2 [OK] Jelastic/MySQL An image of the MySQL database server mainta... 1 WiddPIm /mysql-client Dockerized mysql Client (5.7) including Curl... 0 [OK] monasca/mysql-init A minimal decoupled init containerfor mysql    0

Copy the code

Check the first search result is mysql, and identify the official product, can be assured to download.

  • Generally, the official image will provide multiple versions. The specific version can be synchronized with the official version or viewed on docker Hub

Docker official provides to view the remote version of the command

You can use this link: hub.docker.com/_/mysql?tab…

  • Use the pull command to download the image to the local PC
╭ ─ ~ / ShopeeWorkspace/NodejsWorkspace/ops - data - be ‹ lei. Liao/SPPC - 10092 / listing - the overview - 1.1 * holds the ╰ ─ ➤ docker pull mysql: 8.0 to 1 Pulling From Library /mysql AFB6EC6FDC1c: Downloading [============>] 7.027MB/27.1MB 0bdC5971ba40: Download complete 97ae94a2c729: Download complete f777521d340e: Download complete 1393ff7fc871: Download complete a499b89994D9: Downloading complete a499b89994D9: Downloading complete a499b89994D9: Downloading complete [==========>] Downloading 2.932MB/13.44MB 7ebe8eefbafe: Download complete 597069368ef1: Waiting ce39a5501878: Waiting 7d545bca14bf: Waiting 211e5bb2ae7b: Waiting 5914e537c077: Waiting + view local mirror ` ` ` bash ╭ ─ ~ / ShopeeWorkspace/NodejsWorkspace/ops - data - be ‹ lei. Liao/SPPC - 10092 / listing - the overview - 1.1 * holds the ╰ ─ ➤ Docker Images REPOSITORY TAG IMAGE ID CREATED SIZE mysql 8.0 30F937e841C8 3 days ago 541MB mysql 5.73346bdf465 11 days ago 448MB mysql latest a7a67c95e831 3 weeks ago 541MB nginx latest 231d40e811cd        6 months ago        126MB
hello-world         latest              fce289e99eb9        17 months ago       1.84kB
Copy the code

Docker RMI can be deleted locally, with the IMAGE ID

╭ ─ ~ / ShopeeWorkspace/NodejsWorkspace/themis - be ‹ dev holds the ╰ ─ ➤ docker rmi a7a67c95e831 Untagged: mysql: latest Untagged: mysql@sha256:61a2a33f4b8b4bc93b7b6b9e65e64044aaec594809f818aeffbff69a893d1944 Deleted: sha256:a7a67c95e83189d60dd24cfeb13d9f235a95a7afd7749a7d09845f303fab239c Deleted: sha256:7972c7c2b8269f6d954cae13742dea63b6b8b960adacfd2d6c4b3c9dd6f9104b Deleted: sha256:417f0df153747fa5ff5860d49b391b3b79b7520c603b3e2e7432ade1dce74666 Deleted: sha256:4f949440ec440d9d25a5e3a00b20f1455112d43960cd4568538f6375702308cb
Deleted: sha256:28ed79ccec804217192861862893dd50c3e0a49ccc6d5c57787d3a709a9a6219
Deleted: sha256:bf971a50a8d9589df4aa7422003999e9f944ff1b9c14f3bf48ed0fa3e21f2a48
Deleted: sha256:af3a3fda5da43f7f03f8b3ca0330d120f9a7e5c0d9c5fc7b738ac45468a7de38
Deleted: sha256:86dceae8843638ef500e2a796a326ecb2ba1fd31cff817c4537afb67f04d6ff2
Deleted: sha256:2021ba03e116f319f5e8a90e3498d338ed213f1e036f59ffacc98266e7d3da6b
Deleted: sha256:3a3e1773b14d8b704f018b086292f46309cc27535f7484e0dfbf5a4308c81202
Deleted: sha256:372a8a077b4e29fa382990aeee3e38181481043fe145cb979ccd52588b4f36be
Deleted: sha256:821bf1f5688724dd59945682c34c0d33694af9c554cc1c3c69ca3aa9ba5d79ea
Deleted: sha256:c2adabaecedbda0af72b153c6499a0555f3a769d52370469d8f6bd6328af9b13
Copy the code

If a message is displayed indicating that the image has been occupied, stop and rm the container, and then rmI.

Ps-a can view all containers

╭ ─ ~ / ShopeeWorkspace/NodejsWorkspace/themis - be ‹ dev holds the ╰ ─ ➤ docker ps-a1 Trigger CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES A23404b6a225 mysql:5.7"Docker - entrypoint. S..."10 days ago Up 10 days 0.0.0.0:3306->3306/ TCP, 33060/ TCP mysql-LEi-5.7 298bdf4cd729        mysql               "Docker - entrypoint. S..."   11 days ago         Exited (0) 10 days ago                                        mysql-lei
8a2da3ec4ed4        hello-world         "/hello"5 have a line Exited (0) 5 have a line elastic_murdock ╭ ─ ~ / ShopeeWorkspace/NodejsWorkspace/themis - be ‹ dev holds the ╰ ─ ➤ docker stop  298bdf4cd729
298bdf4cd729 ╭ ─ ~ / ShopeeWorkspace/NodejsWorkspace/themis - be ‹ dev holds the ╰ ─ ➤ docker rm mysql - lei mysql - leiCopy the code
  • userunCommand to start a mirror
╭ ─ ~ / ShopeeWorkspace/NodejsWorkspace/themis - be ‹ dev holds the ╰ ─ ➤ docker run - name = mysql 8.0-e MYSQL_ROOT_HOST=% -e MYSQL_ROOT_PASSWORD=123456 -p 6606:6606 -dMysql: 8.0 a9c2c5992a712dfe4cf615e00332c83f610624543c441b02fc34028a6d8a520b
Copy the code

–name Specifies the name of the container and is used for subsequent startup. -p Maps the ports of the container and the native

  • Logs command to check whether the container is running properly
─ ~ / ShopeeWorkspace/NodejsWorkspace/themis - be ‹ dev holds the ╰ ─ ➤ docker logs 07:57:53 + mysql 8.0 2020-05-25 00:00 [Note] [Entrypoint]: Entrypoint scriptfor MySQL Server 8.0.20-1debian10 started.
2020-05-25 07:57:53+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-05-25 07:57:53+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
2020-05-25 07:57:53+00:00 [Note] [Entrypoint]: Initializing database files
Copy the code
  • useexecInto the container
╭ ─ ~ / ShopeeWorkspace/NodejsWorkspace/themis - be ‹ dev holds the ╰ ─ ➤ dockerexec-it mysql-8.0 mysql -u root -p Enter password: Welcome to the mysql monitor. Commands end with; or \g. Your MySQL connection id is 8 Server version: 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>
Copy the code
  • You can also enter the container first and then enter the mysql environment
╭ ─ ~ / ShopeeWorkspace/NodejsWorkspace/themis - be ‹ dev holds the ╰ ─ ➤ dockerexec-it mysql-8.0 /bin/bash 130 Address root@a9c2c5992a71:/# mysql -u root -p
Enter password:
Copy the code
  • Mysql > select * from docker where localhost:6606;