Skip to content

docker-compose for Mysql

yml
version: '3'

services:
  db:
    image: mysql:8.0.23
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: <password>  # Change this to a strong password
      MYSQL_DATABASE: <db>  # Change this to your desired database name
      MYSQL_USER: <user>  # Change this to your desired username
      MYSQL_PASSWORD: <password>  # Change this to your desired password
    ports:
      - "3306:3306"
    command:
      --default-authentication-plugin=mysql_native_password
      --lower_case_table_names=1
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci

    volumes:
      - ./dbdata/db_data:/var/lib/mysql
      - /etc/localtime:/etc/localtime
      - ./logs:/var/log/mysql
      - ./mysql-files:/var/lib/mysql-files`
      - ./conf/my.cnf:/etc/mysql/my.cnf
.cnf
[mysqld]
user=mysql
bind-address = 0.0.0.0 # 表示允许任何主机登陆MySQL
port=3306
default-storage-engine=INNODB
#character-set-server=utf8
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
secure-file-priv=

[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

Released under the MIT License.