权限管理
本文最后更新于 50 天前,如有失效请评论区留言。

MySQL授权表

mysql库下的授权表及其放行权限的范围

权限表 作用范围
mysql.user 针对所有数据、所有库下所有表、以及表下的所有字段
msyql.db 针对某一数据库下的所有表,以及表下的所有字段
tables_priv 只针对某一张表、以及该表下的所有字段
columns_priv 只针对某一个字段

授权操作

权限

全部权限:all

  • all,所有权限(默认不带grant权限)
  • all+with grant option:所有权限(带grant)

单个权限:select,update,delete,create....

查看用户权限

show grants for root@'localhost';

授予用户权限

grant 指令:用于授权

#(1)针对所有库的所有表:*.* 
grant select on *.* to 'cuckooyang1'@'localhost' identified by '123'; 

#(2)针对某一数据库:db1.*
grant select on db1.* to 'cuckooyang2'@'%' identified by '123'; 
只在db表中可以查到cuckooyang2用户的select权限被设置为Y

#(3)针对某一个表:db1.t1
grant select on db1.t1 to 'cuckooyang3'@'%' identified by '123';  
只在tables_priv表中可以查到cuckooyang3用户的select权限

#(4)针对某一个字段:
grant select (id,name),update (age) on db1.t3 to 'cuckooyang4'@'localhost' identified by '123'; 

#(5)作用在存储过程上:
grant execute on procedure db1.p1 to 'dba'@'localhost';

#(6)作用在函数上:
grant execute on function db1.f1 to 'dba'@'localhost';

撤销用户权限

revoke all on *.* from 'dba'@'localhost';

扩展权限(了解)

通过grant with关键字授权。

max_queries_per_hour:一个用户每小时可发出的查询数量
max_updates_per_hour:一个用户每小时可发出的更新数量
max_connections_per_hour:一个用户每小时可连接到服务器的次数
max_user_connections:允许同时连接数量

mysql> grant all on *.* to test@'%' identified by '123' with max_user_connections 1;

权限分配

普通用户

grant 普通数据用户,查询、插入、更新、删除数据库中所有表数据的权利。

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

开发人员

grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限,

1、创建、修改、删除表结构的权限

grant alter  on testdb.* to developer@'192.168.0.%';
grant drop   on testdb.* to developer@'192.168.0.%'; 
grant create on testdb.* to developer@'192.168.0.%';

2、操作MySQL外键的权限

grant references on testdb.* to developer@'192.168.0.%';

3、操作临时表

grant create temporary tables on testdb.* to developer@'192.168.0.%';

4、索引

grant index on testdb.* to developer@'192.168.0.%';

5、视图

grant create view on testdb.* to developer@'192.168.0.%';
grant show view on testdb.* to developer@'192.168.0.%';

6、存储过程、函数

grant create routine on testdb.* to developer@'192.168.0.%'; -- now, can show procedure status

grant alter  routine on testdb.* to developer@'192.168.0.%'; -- now, you can drop a procedure

grant execute        on testdb.* to developer@'192.168.0.%';

普通DBA

管理某个数据库的权限

grant all privileges on testdb.* to dba@'localhost'

高级DBA

管理所有数据库

grant all on *.* to dba@'localhost'

超级管理员

拥有root权限

企业中的权限设定

开发人员说:请给我开一个用户

1.首先进行沟通
1.你需要对哪些库、表进行操作
2.你从哪里连接过来
3.用户名有没有要求
4.密码要求
5.你要使用多长时间
6.发邮件

2.一般给开发创建用户权限,建议不给delete权限
grant select,update,delete,insert on *.* to egon@'10.0.0.%'' identified by '123';

3.注意:
开发图方便想要root用户,这玩意,谁给谁背锅,自己斟酌,可以考虑让部门老大来给

版权声明:除特殊说明,博客文章均为cuckooyang原创,依据CC BY-SA 4.0许可证进行授权,转载请附上出处链接及本声明。 | 博客订阅:RSS | 广告招租:留言板 | 博客VPS |
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇