mysql grant用法_mysql grant用法汇总

基础语法,运行与mysql5.0及以上grant 权限 on 数据库对象 to 用户

操作示例及说明mysql> grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option; # 

mysql> grant all privileges on *.* to 'root'@'%'; # >= mysql8.0

--all表示所有权限,也可以是select、insert、delete、update、create、alter、drop...

--第一个*表示所有库,第二个*表示所有表

--root表示用户名,%表示所有访问ip

--password表示root用户的密码

--grant option让被授权用户也拥有授权用户所有权限给其他用户

mysql> flush privileges; --刷新权限

一、数据的增删改查权限--授权testdb用户对testdb库下所有表拥有增、删、改和查权限

grant select, insert, update, delete on testdb.* to test@'%';

--作用在具体的列上

grant select(id,msg,ctime) on testdb.testlog to test@'%';

二、表及表结构的创建、修改、删除、外键、临时表、索引grant create,alter,drop,references,create temporary,index on testdb.* to test@'%';

三、Mysql视图,创建、查看grant create view,show view on testdb.* to test@'%';

四、Mysql操作,函数、存储grant create routine,alter routine on testdb.* to test@'%';

grant execute on testdb.* to test@'%';

--作用在具体的函数上

grant execute on procedure testdb.pr_add to 'dba'@'localhost';

grant execute on function testdb.fn_add to 'dba'@'localhost';

五、查看grant权限--查看当前用户权限

show grants;

--查看其他用户权限

show grants for testdb@'localhost';

六、撤销权限--撤销所有权限

revoke all on *.* from testdb@localhost;

七、从库复制相关权限--在Master主机上执行

grant replication slave,reload,create user,super on *.* to copy_slave@'192.168.1.%' with grant option;

--执行flush logs命令需要reload权限

--执行show master status和show slave status命令需要super或replication client权限

--执行change master to命令需要super权限

八、创建用户create user 'account'@'%' identified by 'password';

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值