docker start installing, configuring MySql

1, the mirror mounting mysql

docker pull mysql/mysql-server

2, docker start container Mysql

docker run --name mysql01 -d -p 3306:3306 mysql/mysql-server

After starting execution:

docker ps 

image-20200101100252880

View root password using the following command

docker logs mysql01

image-20200101100509567

navicat mysql server connection test

image-20200101100821215

The reason: mysql security reasons, root users can only log on locally.

So we need to create a user enters the container and authorization.

And mysql MYSQL_ONETIME_PASSWORD environment variable defaults to true, root user password default can only be used once, we need to change the root password after you log mysql.

Enter the following command mysql container

docker exec -it mysql01 bash

image-20200101101153497

Enter the following command mysql interactive mode, just enter the password docker logs mysql01

mysql uroot -p

image-20200101101250796

change Password

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

Create user authorization. % Represents any address can connect to the server.

CREATE USER 'LZL'@'%' IDENTIFIED BY 'pwd123456';

GRANT ALL PRIVILEGES ON *.* TO 'LZL'@'%' WITH GRANT OPTION;

Use navicat connected again to succeed.

image-20200101102956619

3, the above is cumbersome, needs to enter mysql want to modify the corresponding settings, following a command to all of the configuration information. Including the character set, the user, their password. -d -e environmental variables and the container running in background mode -p port mapping --character-set-server for the character set mysql

docker run -d -p 3306:3306 
-e MYSQL_USER="lzl" 
-e MYSQL_PASSWORD="password" 
-e MYSQL_ROOT_PASSWORD="password" 
--name mysql01 
mysql/mysql-server 
--character-set-server=utf8 
--collation-server=utf8_general_ci

Guess you like

Origin www.cnblogs.com/roluodev/p/12128518.html