docker-compose运行mysql 8.0.2

docker-compose.yaml

version: '3.9'

services:
  mysql:
    image: mysql:8.0.32
    container_name: mysql
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    environment:
      DB_PORT: $DB_PORT
      MYSQL_ROOT_PASSWORD: $DB_PASSWORD
      MYSQL_DATABASE: $DB_NAME
    volumes:
      - ./my.cnf:/etc/mysql/my.cnf
      - ./mysql/data:/var/lib/mysql
    healthcheck:
      test: "mysql -h127.0.0.1 -P$$DB_PORT -uroot -p$$MYSQL_ROOT_PASSWORD -e 'ping'"
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 30s
    networks:
      - mysql
networks:
  mysql:
    driver: bridge

创建用户名

CREATE USER 'test'@'%' identified with mysql_native_password by '12345678';

my.cnf 样例

[client]
port=3306
default-character-set = utf8mb4
socket=/data/apps/mysql/mysql.sock
safe-updates

[mysqld]
character-set-server=utf8mb4
# require_secure_transport=ON
#default_password_lifetime=90
log_timestamps = SYSTEM
port=3306
datadir=/data/apps/mysql/data
pid_file=/data/apps/mysql/mysqld.pid
socket=/data/apps/mysql/mysql.sock
skip-external-locking
#net_read_timeout=120
#net_write_timeout=120
key_buffer_size = 16K
max_allowed_packet = 1G
max_connections = 5000
#interactive_timeout = 120
wait_timeout = 28800
user=mysql
local_infile=OFF
#secure_file_priv=/data/apps/mysql/data
table_open_cache = 4
sort_buffer_size = 4M
read_buffer_size = 8M
read_rnd_buffer_size = 8M
join_buffer_size = 4M
net_buffer_length = 2K
thread_stack = 512K
thread_cache_size = 16
key_buffer_size = 4M
skip_name_resolve=ON
innodb_file_per_table = ON
log-bin=/data/apps/mysql/logs/mysql-bin
tmpdir=/data/apps/mysql/tmp
server-id=100
sync_binlog=1
#log_replica_updates=1
binlog-ignore-db=mysql
#binlog_expire_logs_seconds=3600
tls_version=TLSv1.2
innodb_flush_log_at_trx_commit=1

default_authentication_plugin = mysql_native_password

log_error = /data/apps/mysql/logs/error.log
slow_query_log = 1
slow_query_log_file = /data/apps/mysql/logs/slow.log
long_query_time = 2

explicit_defaults_for_timestamp=true
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

[mysqldump]
quick
max_allowed_packet = 160M
[mysql]
no-auto-rehash
prompt = mysql[\d]>
default-character-set=utf8
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
posted @ 2023-04-07 17:28  小吉猫  阅读(208)  评论(0编辑  收藏  举报