One, install mysql 8
(1) Mirror
docker pull mysql:8.0.22
No internet: export and import
docker save mysql:8.0.22 -o /home/mysql
docker load -i /home/mysql
(2) Operation
- View the list of startup commands, configuration options,
docker run -it --rm mysql:8.0.22 --verbose --help
docker run -d --name mysql \
-p 15003:3306 -e MYSQL_ROOT_PASSWORD=root \
--restart always mysql:8.0.22 \
--lower-case-table-names=1 \
--default-authentication-plugin=mysql_native_password
// Command to update container parameters: docker container update parameter container name, such as: update restart
docker container update --restart=always mysql
docker container update --restart=no mysql
// change time zone
https://blog.csdn.net/why_still_confused/article/details/88936664
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
// The file is changed and exploded, just copy it out, change it and put it back
docker cp mysql:/etc/profile /home/profile
docker cp /home/profile mysql:/etc/profile
// Create function error 1418
set global log_bin_trust_function_creators=1;
(3) Change permissions
1. Enter the container
docker exec -it mysql /bin/bash
2. Log in locally
// Log in after a while, wait until mysql is fully started
mysql -u root -p
(input password)
3. To create an account
// Some versions must be entered first: use mysql;
create user'admin'@'%' identified by'root';
Give all permissions
// with grant option allows the propagation of permissions, you can omit
grant all on *.* to'admin'@'%' with grant option;
The password does not
expire ALTER USER'admin'@'%' PASSWORD EXPIRE NEVER;
Modify the encryption rules
ALTER USER'admin'@'%' IDENTIFIED WITH mysql_native_password BY'root';
Refresh effective
FLUSH PRIVILEGES;
Enter exit, which can be used to exit the mysql command line or container