目录结构
docker-compose.yml
version: '3.4'
services:
mysql:
image: mysql:5.7.35
container_name: mysql
hostname: mysql
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: Abc@123456
volumes:
#设置时区使用宿主机时区,防止时间少8小时
- ./localtime:/etc/localtime:ro
- ./data:/var/lib/mysql
- ./config:/etc/mysql/conf.d
- ./log:/var/log/mysql/
- ./init:/docker-entrypoint-initdb.d/
- ./mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
command:
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_unicode_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_allowed_packet=128M
--default-time-zone='+8:00'
networks:
test:
ipv4_address: 172.18.0.10
networks:
test:
external: true
mysqld.cnf
# Copyright (c) 2014, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
federated
init.sql
CREATE DATABASE IF NOT EXISTS nacos_config DEFAULT CHARACTER SET = 'utf8mb4';
CREATE USER 'renkaige'@'%' IDENTIFIED BY 'Abc@123456';
GRANT ALL ON nacos_config.* TO 'renkaige'@'%' IDENTIFIED BY 'Abc@123456';
mysql.conf
[mysqld]
character-set-server=utf8mb4
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
localtime
可以从服务器的/etc/localtime获取