mysql 账号/表授权问题 grant

一、授权格式:

grant 权限 on 数据库对象 to 用户  [identified by '密码']

> 权限可以是all, select, insert, update, delete、
> 		references 外键、index索引
> 		create view、show view
> 		存储过程 函数 create routine、alter routine、execute
> 		
> 密码要用 单/双引号 括起来
> 例如:grant all on *.* to slave@192.168.0.10 identified by 'funsion';
> 用户可以是 test@192.168.1.9, % 代表给所有IP开放权限
> 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

> grant 普通 DBA 管理某个 MySQL 数据库的权限。 关键字 privileges 可以省略。
grant all privileges on testdb to dba@'localhost'

给账号表授权

grant  all on *.* to   dba@localhost;

二、MySQL grant 权限,分别可以作用在多个层次上。

  1. grant 作用在整个 MySQL 服务器上:
grant select on *.* to dba@localhost; 
>  dba 可以查询 MySQL 中所有数据库中的表。
>  
grant all on *.* to dba@localhost; 
>   dba 可以管理 MySQL 中的所有数据库
  1. grant 作用在单个数据库上:

复制代码代码如下:

grant select on testdb.* to dba@localhost;

>  dba 可以查询 testdb 中的表。
  1. grant 作用在单个数据表上:
grant select, insert, update, delete on testdb.orders to dba@localhost;

三、 查看 MySQL 用户权限

查看当前用户(自己)权限:

show grants;

查看其他 MySQL 用户权限:

show grants for dba@localhost;

四、撤销已经赋予给 MySQL 用户权限的权限。

revoke 跟 grant 的语法差不多,只需要把关键字 to 换成 from 即可:

grant  all on *.* to   dba@localhost;
revoke all on *.* from dba@localhost;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值