• docker-compose.yml
version: '3.8'
services:
  mysql:
    image: mysql:5.7.26
    restart: always
    #network_mode: host
    container_name: mysql_1022
    volumes: 
      - ./datadir:/var/lib/mysql
      - ./my.cnf:/etc/mysql/my.cnf
      - ./conf.d:/etc/mysql/conf.d
      #- ./sql:/docker-entrypoint-initdb.d  #数据库自动导入
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_USER=lren
      - MYSQL_PASS=lren.org
  • 初始化mysql
docker exec -it mysql5735 /bin/bash

mysql -u root -p
select curtime(); 
show variables like "%time_zone%";
select @@sql_mode;

在控制台执行 mysql -u root -p mysql
在mysql控制台执行
GRANT ALL PRIVILEGES ON *.* TO "root"@"%" IDENTIFIED BY "example" WITH GRANT OPTION;
FLUSH PRIVILEGES;

ALTER USER 'root'@'localhost' IDENTIFIED BY 'example';

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