ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

2.3.3 mysql 权限系统介绍

2021-06-02 17:57:51  阅读:178  来源: 互联网

标签:grant ADMIN privileges flush user mysql 2.3 权限 localhost


授权案例总结

host 列: %,localhost,127.0.0.1,::1

1)授权普通用户,具有查询、插入、更新、删除 itpux 这个数据库所有表数据的权限。
grant select, insert, update, delete on itpux.* to itpux1@'%';

flush privileges;
show grants for itpux1@'%'


2)开发人员授权:创建/删除/修改-表/索引/视图/存储过程/函数等权限
create user dev@'%' identified by 'dev';
grant create,alter,drop on itpux1.* to dev@'%';
flush privileges;
show grants for dev@'%';


create user dev@'10.0.0.%' identified by 'dev';
grant create,alter,drop on itpux1.* to dev@'10.0.0.%';
flush privileges;
show grant for dev@'10.0.0.%';


3)操作mysql外键的权限
grant references on itpux1.* to dev@'%';
flush privileges;


4)操作mysql临时表的权限
grant create temporary tables on itpux1.* to dev@'%';
flush privileges;
5)操作mysql索引的权限
grant index on itpux1.* to dev@'%';
flush privileges;


6)操作mysql视图的权限
grant create view,show view on itpux1.* to dev@'%';
flush privileges;
7)操作mysql存储过程/函数的权限
grant create routine,alter routine,execute on itpux1.* to dev@'%';


8)授权一个普通的dba用户,可以管理某一个数据库
grant all privileges on itpux to itpuxdba@'localhost' identified by 'itpuxdba';
flush privileges;


9)授权一个高级的dba用户,可以管理所有的数据库
grant all privileges on *.* to alldba@'localhost' identified by 'alldba';
flush privileges;


10)授权针对所有的数据库
grant all privileges on *.* to alldba@'localhost';
flush privileges;


11)授权针对单个的数据库
grant all privileges on itpux to alldbae'LocaLhost'i
grant select on itpux.* to alldba@'localhost';
flush privileges;


12)授权针对所有的数据库
grant select on itpux.* to alldba@'locaLhost';
flush privileges;


13)授权针对单个列
grant select(deptno,dname) on itpux.dept to alldba@'localhost';
flush privileges;


14)授权针对存储过程和函数
grant execute on procedure 库名.过程名 to alldba@'localhost';
grant execute on function 库名.函数名 to alldba@'localhost';
flush privileges;

 

revoke 语法

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

1)授权针对所有的数据库
revoke revoke all privileges on *.* from alldba@'localhost';
flush privileges;

2)授权针对单个的数据库
revoke all privileges on itpux.* from alldba@'locaLhost';
revoke select on itpux.* from alldba@'localhost';
flush privileges;

3)授权针对所有的数据库
revoke select on itpux.* from alldba@'locaLhost';
flush privileges;

4)授权针对单个列
revoke select(deptno,dname) on itpux.dept from alldba@'localhost';
flush privileges;

5)授权针对存储过程和函数
revoke execute on procedure 库名.过程名 from alldba@'localhost';
revoke execute on function 库名.函数名 from alldba@'localhost';
flush privileges;


show grants for alldba@'localhost'
show grants for itpux1@'localhost'

 

另类方法:直接修改授权表回收授权-不建议使用

select user,host from mysql.user
delete from mysql.user where user='alldba' and host='localhost';
commit;
flush privileges;
select user,host from mysql.user;

删除用户及重命名用户

select user,host from mysql.user;
drop user dev;
drop user dev@'%';
drop user dev@'192.168.1.%';
select user,host from mysql.user where user like 'dev%';
select user,host from mysql.user;
rename user 'itpuxdba'@'localhost' to 'itpuxdba1'@'localhost';

 

显示授权

show grants for itpux;
show grants for itpux@localhost;
select * from mysql.user where user='itpux1' and host='localhost';

select CURRENT_USER();

show grants;
show grants for current_user;


mysql root@localhost:mysql> show grants for current_user\G
***************************[ 1. row ]***************************
Grants for root@localhost | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES,
 SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, 
CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION
***************************[ 2. row ]***************************
Grants for root@localhost | GRANT APPLICATION_PASSWORD_ADMIN,AUDIT_ADMIN,BACKUP_ADMIN,BINLOG_ADMIN,BINLOG_ENCRYPTION_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,
GROUP_REPLICATION_ADMIN,INNODB_REDO_LOG_ARCHIVE,INNODB_REDO_LOG_ENABLE,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_APPLIER,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,
SERVICE_CONNECTION_ADMIN,SESSION_VARIABLES_ADMIN,SET_USER_ID,SHOW_ROUTINE,SYSTEM_USER,SYSTEM_VARIABLES_ADMIN,TABLE_ENCRYPTION_ADMIN,XA_RECOVER_ADMIN ON *.* TO `root`@`localhost` WITH GRANT OPTION
***************************[ 3. row ]***************************
Grants for root@localhost | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION

 

标签:grant,ADMIN,privileges,flush,user,mysql,2.3,权限,localhost
来源: https://blog.51cto.com/wenyule/2847595

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有