docker pull mysql/mysql-server
docker run -d -p 3306:3306 --name [Name] [ImageName] //示例 docker run -d -p 3306:3306 --name mysql01 mysql/mysql-server
docker exec -it [ContainerName] bash //示例 docker exec -it mysql01 bash
mysql -uroot -p
mysql> CREATE USER 'test'@'localhost' IDENTIFIED BY 'pwd123456'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost' WITH GRANT OPTION; mysql> CREATE USER 'test'@'%' IDENTIFIED BY 'pwd123456'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' WITH GRAN T OPTION;
[mysqld] character-set-server=utf8 [client] default-character-set=utf8 [mysql] default-character-set=utf8
show variables like '%char%';
docker run -d -p 3306:3306 -e MYSQL_USER="test" -e MYSQL_PASSWORD="password" -e MYSQL_ROOT_PASSWORD="password" --name [Name] [ImageName] --character-set-server=utf8 --collation-server=utf8_general_ci
docker run -d -p 3306:3306 -e MYSQL_USER="test" -e MYSQL_PASSWORD="password" -e MYSQL_ROOT_PASSWORD="password" --name [Name] [ImageName] --character-set-server=utf8 --collation-server=utf8_general_ci
[mysqld] user=mysql character-set-server=utf8 [client] default-character-set=utf8 [mysql] default-character-set=utf8
docker run -d -p 3306:3306 --name mysql01 -v=/docker/mysql/config/my.cnf:/etc/my.cnf -v=/docker/mysql/config/data:/var/lib/mysql mysql/mysql-server
docker run -d -p 27017:27017 --name mongo01 -v /docker/mongo/config:/data/configdb -v /docker/mongo/db:/data/db mongo
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password');
ALTER user 'root'@'localhost' IDENTIFIED BY 'password'
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;
备注: : When this is true (which is its default state, unless MYSQL_ROOT_PASSWORD is set or MYSQL_ALLOW_EMPTY_PASSWORD is set to true), a random password for the server's root user is generated when the Docker container is started
当这个MYSQL_RANDOM_ROOT_PASSWORD 为true 时 为root用户设置密码是没有作用的还是会生成随机的密码,设置为false 或者不加这个环境变量
来源:https://www.cnblogs.com/shitong/p/10148851.html