MySQL installation tutorial of Docker series

MySQL installation tutorial of Docker series With the previous basic tutorial Common command operation manual of Docker series After that, this blog records a mysql installation tutorial

mysql image query command

docker search mysql

Several key parameters are explained as follows:

  • INDEX docker.io is the official website of docker
  • NAME the NAME of the image
  • DESCRIPTION image DESCRIPTION
  • STARS attention
  • OFFICIAL or not
  • Automatic or not

INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/mysql MySQL is a widely used, open-source relati... 8930 [OK]
docker.io docker.io/mariadb MariaDB is a community-developed fork of M... 3140 [OK]
docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... 659 [OK] docker.io docker.io/percona Percona Server is a fork of the MySQL rela... 462 [OK]
docker.io docker.io/centos/mysql-57-centos7 MySQL 5.7 SQL database server 66
docker.io docker.io/centurylink/mysql Image containing mysql. Optimized to be li... 61 [OK] docker.io docker.io/mysql/mysql-cluster Experimental MySQL Cluster Docker images. ... 59
docker.io docker.io/deitch/mysql-backup REPLACED! Please use http://hub.docker.com... 41 [OK] docker.io docker.io/bitnami/mysql Bitnami MySQL Docker Image 35 [OK] docker.io docker.io/tutum/mysql Base docker image to run a MySQL database ... 34
docker.io docker.io/schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... 28 [OK] docker.io docker.io/prom/mysqld-exporter 23 [OK] docker.io docker.io/linuxserver/mysql A Mysql container, brought to you by Linux... 22
docker.io docker.io/centos/mysql-56-centos7 MySQL 5.6 SQL database server 17
docker.io docker.io/circleci/mysql MySQL is a widely used, open-source relati... 16
docker.io docker.io/mysql/mysql-router MySQL Router provides transparent routing ... 14
docker.io docker.io/arey/mysql-client Run a MySQL client from a docker container 13 [OK] docker.io docker.io/openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 ima... 6
docker.io docker.io/fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron t... 4 [OK] docker.io docker.io/genschsa/mysql-employees MySQL Employee Sample Database 3 [OK] docker.io docker.io/ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK] docker.io docker.io/devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offi... 2
docker.io docker.io/jelastic/mysql An image of the MySQL database server main... 1
docker.io docker.io/monasca/mysql-init A minimal decoupled init container for mysql 0
docker.io docker.io/widdpim/mysql-client Dockerized MySQL Client (5.7) including Cu... 0 [OK] [root@localhost ~]#

mysql image pull

# Do not specify version, default latest version
docker pull mysql

View the local warehouse image list

docker images

Run mysql container

docker run --name mysql01 -d mysql

View running containers

docker ps

Found no mysql container running View all containers

docker ps -a

Found that mysql container did not start successfully View the log of the corresponding container

docker logs c1a7aceff20b

It is found that the following error is reported, which means to specify one of MySQL ﹣ root ﹣ password, MySQL ﹣ allow ﹣ empty ﹣ password and MySQL ﹣ random ﹣ root ﹣ password, which means to set password, allow empty password, or randomly generate password

Delete container

docker rm c1a7aceff20b

View all containers

docker ps -a

Start the container again and specify port mapping 3306

docker run -p 3306:3306 --name mysql02 -e MYSQL_ROOT_PASSWORD=11 -d mysql

View. The container starts successfully. If the name is duplicate, you can specify another name Look at the official documents and find the startup method of the specified code

docker run -p 3306:3306 --name mysql02 -e MYSQL_ROOT_PASSWORD=11 -d mysql --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

Because it is the latest version, the client will prompt an error when logging in:

Error No.2058 Plugin caching_sha2_password could not be loaded

The solution is to modify the encryption method and enter the mysql container

docker exec -it mysql02 bash

mysql root login

mysql -u root -p

Modify encryption rules

#Modify encryption rules 
ALTER USER 'root'@'%' IDENTIFIED BY '11' PASSWORD EXPIRE NEVER;

For learning, you can specify 'root' @ '%, which means all ip can be accessed. For production security, you can specify ip

#Update the user's password 
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '11'; 

Need to refresh permissions to work

 #Refresh permissions
FLUSH PRIVILEGES;

Restart the password, or you can ignore it

# reset password 
alter user 'root'@'%' identified by '11';

Login test again successful Other operations:

# Mount the / conf/mysql folder of the host to the / etc/mysql/conf.d folder of the mysql docker container. To change the mysql configuration file, you only need to put the mysql configuration file in / conf/mysql
docker run ‐‐name mysql03 ‐v /conf/mysql:/etc/mysql/conf.d ‐e MYSQL_ROOT_PASSWORD=my‐secret‐pw
‐d mysql:tag

For detailed operation, please refer to Official Docker manual , for introduction and other docker tutorials, please refer to my Docker blog column

Tags: Programming Docker MySQL Database MariaDB

Posted on Tue, 21 Apr 2020 08:40:31 -0700 by mark_c