MySQL5

services:
  mysql5:
    container_name: mysql5
    restart: always
    network_mode: host
    volumes:
      - /mnt/user/02Database/mysql5/log:/var/log/mysql
      - /mnt/user/02Database/mysql5/data:/var/lib/mysql
      - /mnt/user/02Database/mysql5/conf.d:/etc/mysql/conf.d
    environment:
      - MYSQL_ROOT_PASSWORD=xxxxx
      - MYSQL_TCP_PORT=3306
      - TZ=Asia/Shanghai
    image: mysql:5.7

mysql -u root -p -P 3306

-- 创建名称为“wandbdata”数据库,并设定编码集为utf8
CREATE DATABASE IF NOT EXISTS wandbdata DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
-- 创建了一个名为:wandb 密码为:wandb123 的用户,将"localhost"改为"%",表示在任何一台电脑上都可以登录。
create user 'wandb'@'localhost' identified by 'wandb123';
 
select user from mysql.user;
-- 授予用户wandb通过localhost/外网IP(改为%)对数据库“testdb”的全部权限
grant all privileges on wandbdata.* to 'wandb'@localhost identified by "wandb123";
flush privileges; #刷新系统权限表
select * from information_schema.user_privileges;
 
-- 修改host
 
update mysql.user set host = '%' where user = 'wandb';
 
grant all on wandbdata.* to 'wandb'@'%' identified by "wandb123";
flush privileges; #刷新系统权限表
select * from information_schema.user_privileges;

MySQL8

services:
  mysql8:
    network_mode: host
    container_name: mysql8
    environment:
      - MYSQL_ROOT_PASSWORD=xxxxxxx
      - MYSQL_TCP_PORT=xxxxx
      - TZ=Asia/Shanghai
    volumes:
      - /mnt/user/02Database/mysql8/log:/var/log/mysql
      - /mnt/user/02Database/mysql8/data:/var/lib/mysql
      - /mnt/user/02Database/mysql8/my.cnf:/etc/mysql/conf.d/my.cnf
      - /mnt/user/02Database/mysql8/sql:/docker-entrypoint-initdb.d
    command: mysqld --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    image: mysql:8.0
-- 创建数据库
-- utf8mb4_general_ci 在比较和排序的时候更快,utf8mb4_unicode_ci 是基于标准的 Unicode 来排序和比较,能够在各种语言之间精确排序
CREATE DATABASE `wandbdata` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ;
 
use wandbdata;
-- 创建user
create user 'wandb'@'localhost' identified by 'wandb123';
-- 查看user
use mysql;
select host, user, authentication_string, plugin from user;
use wandbdata;
 
-- 授权
grant all privileges on wandbdata.* to 'wandb'@'localhost';
 
flush privileges;
 
-- 查看用户权限
show grants for 'wandb'@'localhost';
 
-- 修改
update mysql.user set host = '%' where user = 'wandb';
flush privileges;
use wandbdata;
grant all privileges on wandbdata.* to 'wandb'@'%';
flush privileges;
 
-- 查看用户权限
show grants for 'wandb'@'%';

为alist

-- utf8mb4_general_ci 在比较和排序的时候更快,utf8mb4_unicode_ci 是基于标准的 Unicode 来排序和比较,能够在各种语言之间精确排序
CREATE DATABASE `alistdata` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ;
 
use alistdata;
 
-- 创建user
create user 'alist'@'localhost' identified by 'alist123';
flush privileges;
-- 查看user
use mysql;
select host, user, authentication_string, plugin from user;
use alistdata;
 
-- 授权
grant all privileges on alistdata.* to 'alist'@'localhost';
 
flush privileges;
 
-- 修改
update mysql.user set host = '%' where user = 'alist';
flush privileges;
 
use alistdata;
grant all privileges on alistdata.* to 'alist'@'%';
flush privileges;
 
-- 查看用户权限
show grants for 'alist'@'%';

为we-mp-rss

CREATE DATABASE `wemprssdata` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ;
use wemprssdata;
 
-- 创建user
create user 'wemprss'@'%' identified by 'wemprss123';
flush privileges;
-- 授权
grant all privileges on wemprssdata.* to 'wemprss'@'%';
flush privileges;
-- 查看user
use mysql;
select host, user, authentication_string, plugin from user;
-- 查看用户权限
show grants for 'wemprss'@'%';