• docker pull mariadb:10.6.4

  • docker-compose.yml

    version: '3.8'
    services:
    mariadb:
      image: mariadb:10.6.4
      restart: always
      #network_mode: host
      container_name: mariadb_1022
      volumes: 
        - ./datadir:/var/lib/mysql
        - ./mariadb.conf.d:/etc/mysql/mariadb.conf.d
      ports:
        - "3306:3306"
      environment:
        - MYSQL_ROOT_PASSWORD=root
    

  • my.cnf
[mysqld]

default-storage-engine=MyIsAM
init_connect='SET NAMES utf8mb4'
sql_mode=''
  • 说明
cmd进入容器内部
docker exec -it mariadb1 bash
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'lren.org';

CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'lren.org';
GRANT ALL PRIVILEGES ON *.* TO 'liaozesong'@'%';