Answer

问题及解答

MySQL 中授权

Posted by haifeng on 2018-11-29 09:14:53 last update 2018-11-29 09:18:21 | Edit | Answers (0)

首先创建一个用户,

mysql> CREATE USER haifeng@localhost IDENTIFIED BY 'TheSecretPasswd';

 

然后赋予其权限, 比如使得用户 haifeng 可以管理 info 和 math 两个数据库.


mysql> GRANT ALL ON info.* TO haifeng@localhost;

mysql> GRANT ALL ON math.* TO haifeng@localhost;
 

也可以一开始就使用 GRANT 语句创建用户并授予权限:

mysql> GRANT ALL ON info.* TO haifeng@localhost IDENTIFIED BY 'TheSecretPasswd';

 

一般的用法是:

GRANT privileges ON db.table TO user@host [IDENTIFIED BY 'password'] [, user [IDENTIFIED BY 'password']] [WITH GRANT OPTION];

 

这里 privileges 表示赋予用户的权限类型.