基础语法,运行与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';