当前位置: 代码网 > it编程>数据库>Mysql > 详解如何对MySQL数据库进行授权管理

详解如何对MySQL数据库进行授权管理

2024年11月20日 Mysql 我要评论
前言看过博主上一篇的盆友,可以get到一个知识点:数据授权(eg:grant xx to yy)。对了,数据这么敏感,必须遵循“分而治之,最小认领”的原则。在这个大数据盛行的时

前言

看过博主上一篇的盆友,可以get到一个知识点:数据授权(eg:grant xx to yy)。对了,数据这么敏感,必须遵循“分而治之,最小认领”的原则。在这个大数据盛行的时代,数据显然成为人类的第n个生产资料,没有它,好像我们“站得不太高,看得不够清,听得不够远”。所以如何管理它,越来越重要了。

今天博主继续大话mysql,助你了解它是如何完成授权的。let’s go~

q:如何对mysql数据库进行授权管理

提示:本文示例均已mysql5.7为例。

一、mysql的“特权”

在学习如何授权前,咱们先来看看mysql有哪些“可授之权”

1. 权限级别

级别说明
全局授予最高管理权限。
数据库授予数据库及其内的所有对象的权限。
数据库对象授予数据库对象(如表、索引、视图和存储例程)的权限。

2. 权限清单

为进一步说明mysql可以提供的特权,博主提供一个官方的列表:

权限授权列表作用域
all [privileges]synonym for “all privileges”server administration
alteralter_privtables
alter routinealter_routine_privstored routines
createcreate_privdatabases, tables, or indexes
create routinecreate_routine_privstored routines
create tablespacecreate_tablespace_privserver administration
create temporary tablescreate_tmp_table_privtables
create usercreate_user_privserver administration
create viewcreate_view_privviews
deletedelete_privtables
dropdrop_privdatabases, tables, or views
eventevent_privdatabases
executeexecute_privstored routines
filefile_privfile access on server host
grant optiongrant_privdatabases, tables, or stored routines
indexindex_privtables
insertinsert_privtables or columns
lock tableslock_tables_privdatabases
processprocess_privserver administration
proxysee proxies_priv tableserver administration
referencesreferences_privdatabases or tables
reloadreload_privserver administration
replication clientrepl_client_privserver administration
replication slaverepl_slave_privserver administration
selectselect_privtables or columns
show databasesshow_db_privserver administration
show viewshow_view_privviews
shutdownshutdown_privserver administration
supersuper_privserver administration
triggertrigger_privtables
updateupdate_privtables or columns
usagesynonym for “no privileges”server administration

针对每个授权项,我们可以参考官方指导文档进行学习,直接跳转这里,进行查阅。

二、授权操作

了解了以上的“特权”后,我们可以自由支配它们,分配给适合的人。

1. 查看权限

比如你想查看指定用户(user)的权限,可以通过以下语句完成:

show grants for [user]@[host];

查看用户的非特权属性,可通过以下语句完成:

show create user [user]@[host];

2. 分配权限

分配权限,统一使用以下语句完成:

grant xx privileges on [db_name].[table_name] to [user]@[host] identified by [password] with grant option;

这里博主有必要对这个语句,做一个特别介绍:

  • grant xx privileges
    授权的范围,比如all、select、create等。
  • on [db_name].[table_name]
    授权的对象,比如哪个库,哪个表。
  • to [user]@[host]
    授权的用户访问控制,比如test用户通过127.0.0.1访问数据库。
  • identified by [password]
    授权的用户访问密码。

3. 回收权限

既然有分配,那么就有回收。回收应该怎么操作,可通过以下语句完成:

revoke xx privileges on [db_name].[table_name] from [user]@[host];

这里博主对这个语句,同样做一个特别介绍:

  • revoke xx privileges
    撤销/回收授权的范围,比如all、select、create等。
  • on [db_name].[table_name]
    撤销/回收的对象,比如哪个库,哪个表。
  • from [user]@[host]
    撤销/回收的用户访问控制,比如test用户通过127.0.0.1访问数据库。

结语

本文对mysql的权限操作进行了一定的介绍。希望可对有需要的盆友提供一定的帮助。

到此这篇关于详解如何对mysql数据库进行授权管理的文章就介绍到这了,更多相关mysql数据授权内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com