安装mysql
docker pull mysql:5.7
简单启动:
docker run -itd --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7 --lower_case_table_names=1
创建映射目录:
mkdir -p /home/mysql/conf
mkdir -p /home/mysql/data
mkdir -p /home/mysql/log
在conf目录下创建my.cnf文件
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# 设置东八区时区
default-time_zone = '+8:00'
# 设置密码验证规则,default_authentication_plugin参数已被废弃,改为authentication_policy
#authentication_policy=mysql_native_password
# 限制导入和导出的数据目录
# 为空,不限制导入到处的数据目录;
# 指定目录,必须从该目录导入到处,且MySQL不会自动创建该目录;
# 为NULL,禁止导入与导出功能
#secure_file_priv=/var/lib/mysql
secure_file_priv=
init_connect='SET collation_connection = utf8mb4_general_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
skip-character-set-client-handshake
skip-name-resolve
## 是否区分表名大小写 0区分 1不区分
lower_case_table_names=1
指定配置文件启动:
docker run -itd \
--name mysql \
-p 3306:3306 \
--restart unless-stopped \
-v /home/mysql/log:/var/log/mysql \
-v /home/mysql/data:/var/lib/mysql \
-v /home/mysql/conf:/etc/mysql/conf.d \
-e TZ=Asia/Shanghai \
-e MYSQL_ROOT_PASSWORD=123456 mysql:5.7