Snippets: MySQL: Create User and Grant Privileges

 20th August 2020 at 2:19pm

常见例子:

CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'password';
GRANT ALL ON db1.* TO 'jeffrey'@'localhost';
GRANT SELECT ON db2.invoice TO 'jeffrey'@'localhost';
ALTER USER 'jeffrey'@'localhost' WITH MAX_QUERIES_PER_HOUR 90;

FLUSH PRIVILEGES;

'jeffrey'@'localhost' 的 host 部分可以省略(也可以用 '%' 代替),表示不限制 jeffrey 是在哪台机器访问的。

参考 MySQL 8.0 文档