需求场景:
在开发和测试环境中,或者研究型的环境,对于数据库的安全和稳定性可以稍低一些,那么我们可以通过docker快速部署MySQL服务,降低部署的时间成本。
vim docker-compose.yml
version: '3' services: mysql: restart: always privileged: true image: mysql:8.0 container_name: mysqlServer3306 volumes: - ./db:/var/lib/mysql - ./conf:/etc/mysql/conf.d - ./logs:/logs command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true environment: MYSQL_ROOT_PASSWORD: "zyl.123654" MYSQL_USER: "zyl" MYSQL_PASSWORD: "zyl.123654" MYSQL_INITDB_SKIP_TZINFO: "Asia/Shanghai" ports: - 33106:3306 network_mode: "bridge"
mkdir db conf logs && chmod 777 logs
vim conf/my.cnf
###### [mysql]配置模块 ###### [mysql] # 设置MySQL客户端默认字符集 default-character-set=utf8mb4 socket=/var/lib/mysql/mysql.sock ###### [mysqld]配置模块 ###### [mysqld] port=3306 user=mysql 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 # MySQL8 的密码认证插件 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' # binlog 配置 log-bin = /logs/mysql-bin.log expire-logs-days = 90 max-binlog-size = 500M # server-id 配置 server-id = 1 ###### [client]配置模块 ###### [client] default-character-set=utf8mb4
docker-compose up -d 启动docker-compose
标签:compose,logs,MySQL,server,mysql,######,docker From: https://www.cnblogs.com/zyl88/p/17620976.html