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 is the official website of docker
  • NAME the NAME of the image
  • STARS attention
  • OFFICIAL or not
  • Automatic or not

INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED MySQL is a widely used, open-source relati... 8930 [OK] MariaDB is a community-developed fork of M... 3140 [OK] Optimized MySQL Server Docker images. Crea... 659 [OK] Percona Server is a fork of the MySQL rela... 462 [OK] MySQL 5.7 SQL database server 66 Image containing mysql. Optimized to be li... 61 [OK] Experimental MySQL Cluster Docker images. ... 59 REPLACED! Please use 41 [OK] Bitnami MySQL Docker Image 35 [OK] Base docker image to run a MySQL database ... 34 Backup MySQL to S3 (supports periodic back... 28 [OK] 23 [OK] A Mysql container, brought to you by Linux... 22 MySQL 5.6 SQL database server 17 MySQL is a widely used, open-source relati... 16 MySQL Router provides transparent routing ... 14 Run a MySQL client from a docker container 13 [OK] DEPRECATED: A Centos7 based MySQL v5.5 ima... 6 MySQL/MariaDB database backup using cron t... 4 [OK] MySQL Employee Sample Database 3 [OK] An APB which deploys RHSCL MySQL 2 [OK] Retagged MySQL, MariaDB and PerconaDB offi... 2 An image of the MySQL database server main... 1 A minimal decoupled init container for mysql 0 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 

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

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