docker安装mysql
docker安装mysql
version: '3'
services:
mysql: # 服务名称
image: mysql:8.0
container_name: mysql8
environment:
- MYSQL_ROOT_PASSWORD=123456
# - TZ=Asia/Shanghai
volumes:
- /docker/mysql/log:/var/log/mysql
- /docker/mysql/data:/var/lib/mysql
- /docker/mysql/conf.d:/etc/mysql/conf.d
- /etc/localtime:/etc/localtime:ro
ports:
- 3306:3306 # 指定宿主机端口与容器端口映射关系,宿主机:容器
restart: always # 容器随docker启动自启
mkdir log data conf.d
vi /docker/mysql/conf.d/my.cnf
###### [client]配置模块 ######
[client]
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock
###### [mysql]配置模块 ######
[mysql]
# 设置MySQL客户端默认字符集
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock
###### [mysqld]配置模块 ######
[mysqld]
port=3306
user=mysql
# 设置sql模式 sql_mode模式引起的分组查询出现*this is incompatible with sql_mode=only_full_group_by,这里最好剔除ONLY_FULL_GROUP_BY
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server-id = 1
# MySQL8 的密码认证插件 如果不设置低版本navicat无法连接
default_authentication_plugin=mysql_native_password
# 禁用符号链接以防止各种安全风险
symbolic-links=0
# 允许最大连接数
max_connections=1000
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 表名存储在磁盘是小写的,但是比较的时候是不区分大小写
lower_case_table_names=0
max_allowed_packet=16M
# 设置时区
default-time_zone='+8:00'
License:
CC BY 4.0