docker启动MYSQL8并挂载数据目录

1.创建需要docker挂载的数据目录

mkdir -p /datah/mydata/mysql/conf
mkdir -p /datah/mydata/mysql/data
mkdir -p /datah/mydata/mysql/log
mkdir -p /datah/mydata/mysql/mysql-files

2. 在目录下面 /datah/mydata/mysql/conf 创建配置文件 my.cnf

[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

[mysqld]

character-set-server=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
init_connect='SET NAMES utf8'
max_connections=5000
wait_timeout=20000
max_user_connections=5000
max_allowed_packet=128M
thread_stack=262144


3.安装docker

yum -y install docker
systemctl start docker

4.运行mysql8.0

#! /bin/bash 
docker rm -f mysql8.0 
docker run  --restart=always --privileged=true --name mysql8.0 \
-v /datah/mydata/mysql/conf:/etc/mysql/conf.d \
-v /datah/mydata/mysql/data:/var/lib/mysql \
-v /datah/mydata/mysql/log:/var/log \
-v /datah/mydata/mysql/mysql-files:/var/lib/mysql-files \
-p 39306:3306 -e MYSQL_ROOT_PASSWORD='123456' -d mysql:8.0

5.进入容器

docker exec -it mysql8.0 bash

6.查看运行

docker ps

 

你可能感兴趣的:(MySQL,docker,mysql,容器,mysql8)