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
View root password using the following command
docker logs mysql01
navicat mysql server connection test
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
Enter the following command mysql interactive mode, just enter the password docker logs mysql01
mysql uroot -p
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.
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