创建用户
1 | CREATE USER 'usernaem'@'host' IDENTIFIED BY 'passwd'; |
授权
1 | GRANT privileges ON databasename.tablename TO 'username'@'host'; |
privileges
:用户的操作权限,如SELECT
,INSERT
,UPDATE
等,如果要授予所的权限则使用ALL
tablename
:表名,如果要授予该用户对所有数据库和表的相应操作权限则可用*
表示,如*.*
用以上命令授权的用户不能给其它用户授权,如果想让该用户可以授权,用以下命令:
1 | GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION; |
设置与更改用户密码
1 | SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword'); |
如果是当前登陆用户用:
1 | SET PASSWORD = PASSWORD("newpassword"); |
撤销用户权限
1 | REVOKE privilege ON databasename.tablename FROM 'username'@'host'; |
删除用户
1 | DROP USER 'username'@'host'; |
总结
1 | SHOW GRANTS FOR 'pig'@'%'; |
参考: 1. https://www.jianshu.com/p/d7b9c468f20d