Docker MySQL Container installation notes

Source: Internet
Author: User
Tags docker ps docker run

Basic Steps for MySQL Server Deployment with Docker1 find the right MySQL image, select the appropriate version

Docker search-f stars=3-f is-official=true mysql--find tag for mysql,stars greater than 3 official image

2 Downloads

Docker Pull mysql:5.7

3 run

(1) Docker run-d--name mysql01 mysql:5.7

Note that the view log (Docker logs mysql01) does not start properly and requires the runtime to pass in the specified parameters

Error message: Database is uninitialized and password option was not specified

You need to specify one of Mysql_root_password, Mysql_allow_empty_password and Mysql_random_root_password

(2) Docker run-d-e mysql_root_password=password--name mysql01 mysql:5.7

4 Viewing logs

Docker logs Mysql01

5 Viewing the running situation

Docker PS

6 Accessing the MySQL container

Docker exec–it MYSQL01 Bash

7 Creating a new user

mysql> CREATE USER ' jack ' @ ' localhost ' identified by ' pwd123456 ';

Mysql> Grant all privileges on *. * to ' jack ' @ ' localhost ' with GRANT OPTION;

mysql> CREATE USER ' jack ' @ '% ' identified by ' pwd123456 ';

Mysql> GRANT All privileges on * * to ' jack ' @ '% '

->with GRANT OPTION;

Mysql Configuration and data content Mount volume

Mapping the file system on the Key:host to the files in the Docker container

1 Create a directory of custom directory user store configuration and data in host for mapping the corresponding files in the Docker MySQL container

Like what:

Host Directory

MySQL Docker container directory

/root/software/docker/mysql/config/my.cnf

/etc/my.cnf

/root/software/docker/mysql/data

/var/lib/mysql

Description new MY.CNF file under host requires initial content

MY.CNF:

[Mysqld]

User=mysql

2 run

Docker run-d-P 3307:3307-v=/root/software/docker/mysql/config/my.cnf:/etc/my.cnf-v=/root/software/docker/mysql/ DATA:/VAR/LIB/MYSQL-E Mysql_root_password=password--name mysql01 mysql:5.7

2 Bash Enter mysql01 Docker container, log in to MySQL to view the default character set

> Docker exec-it mysql01 Bash

>mysql–uroot–p

......

>show variables like '%char% ';

Description: Displayed as Lanti character set

3 Modifying the MySQL character set for utf-8, complete by modifying MY.CNF

MY.CNF:

[Mysqld]

User=mysql

Character-set-server=utf8

[Client]

Default-character-set=utf8

[MySQL]

Default-character-set=utf8

4 Delete Current Container

>docker Stop Mysql01

>docker RM mysql01

5 Restarting a new container

Docker run-d-P 3307:3307-v=/root/software/docker/mysql/config/my.cnf:/etc/my.cnf-v=/root/software/docker/mysql/ DATA:/VAR/LIB/MYSQL-E Mysql_root_password=password--name mysql01 mysql:5.7

6 Viewing the character set, the previously modified character set is used by default Utf-8

Description: The configuration is shared, the purpose: The data file will be deleted after the container is deleted, mount can achieve data persistence and sharing

Resources:

Mysql Official website: https://dev.mysql.com/doc/refman/5.7/en/docker-mysql-more-topics.html

Learning Group Graphite Document: https://shimo.im/docs/anrlYMFEYloN52c8/

Xmind Documentation: basic commands for Docker

Docker Command Documentation: Https://docs.docker.com/engine/reference/commandline

Docker MySQL Container installation notes

Related Article

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.