docker启动MySQL数据库

  1. 拉取镜像
docker pull mysql:latest
  1. 启动容器

创建映射目录

mkdir -p /mysql/data

启动

docker run \
--restart=always \
--name mysql-service \
-v /mysql/data:/var/lib/mysql \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=xxss45mysql8 \
-d mysql \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_general_ci \
--lower_case_table_names=1 \
--skip-name-resolve=1 \
--max_connections=1000 \
--wait_timeout=31536000 \
--interactive_timeout=31536000 \
--default-time-zone='+8:00'
  1. 进入容器
docker exec -it mysql-service sh
  1. 创建用户、授权用户等操作
// mysql create user 创建用户
create user 'test'@'%' identified with MYSQL_NATIVE_PASSWORD by 'xxss45mysql8 ';
// grant privileges 授权
GRANT SELECT,ALTER,UPDATE,CREATE,INSERT,DELETE,CREATE TEMPORARY TABLES,DROP,INDEX,REFERENCES,TRIGGER,ALTER ROUTINE,CREATE ROUTINE,CREATE TABLESPACE,CREATE TEMPORARY TABLES,CREATE VIEW,EVENT,EXECUTE,PROCESS,RELOAD,SHOW DATABASES,SHOW VIEW,TRIGGER ON *.* TO 'test'@'%';

你可能感兴趣的:(docker启动MySQL数据库)