MySQL8 创建用户和授权

查看用户

1
SELECT* FROM mysql.user;`

创建用户

1
2
3
CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'password';
CREATE USER 'testuser'@'192.168.10.100' IDENTIFIED BY 'password';
CREATE USER 'testuser'@'%' IDENTIFIED BY 'password';

授权

1
2
3
GRANT ALL PRIVILEGES ON testdb.* TO 'testuser'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'localhost';
GRANT SELECT, INSERT, DELETE ON testdb1.* TO testuser@'localhost';

持久化权限配置

一般不需要执行

grant 之后要跟着 flush privileges 吗?-极客时间

1
flush privileges;

查看权限

1
SHOW GRANTS FOR 'testuser'@'localhost';