iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >MySQL赋予用户的各种数据库操作权限
  • 913
分享到

MySQL赋予用户的各种数据库操作权限

数据库 2023-08-31 06:08:44 913人浏览 独家记忆
摘要

Mysql清空数据库的操作:truncate table tablename; mysql 赋予用户权限命令的简单格式可概括为:grant 权限 on 数据库对象 to 用户 一、grant 普通数据用户,查询、插入、更新、删除 数据库中所

Mysql清空数据库的操作:truncate table tablename;

mysql 赋予用户权限命令的简单格式可概括为:grant 权限 on 数据库对象 to 用户

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

 grant select on testdb.* to common_user@'%' grant insert on testdb.* to common_user@'%' grant update on testdb.* to common_user@'%' grant delete on testdb.* to common_user@'%'
或者,用一条 Mysql 命令来替代:

 grant select, insert, update, delete on testdb.* to common_user@'%'
二、grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。

grant 创建、修改、删除 MySQL 数据表结构权限

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

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

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

grant 操作 MySQL 外键权限

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

grant 操作 MySQL 临时表权限

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

grant 操作 MySQL 索引权限

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

grant 操作 MySQL 视图、查看视图源代码权限

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

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

grant 操作 MySQL 存储过程、函数权限

 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.%' ;

三、grant 普通 DBA 管理某个 MySQL 数据库的权限

grant all privileges on testdb to dba@'localhost' 其中,关键字 “privileges” 可以省略。

四、grant 高级 DBA 管理 MySQL 中所有数据库的权限

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

五、MySQL grant 权限,分别可以作用在多个层次上

grant 作用在整个 MySQL 服务器上:
grant select on *.* to dba@localhost ; -- dba 可以查询 MySQL 中所有数据库中的表。

grant all on *.* to dba@localhost ; -- dba 可以管理 MySQL 中的所有数据库

grant 作用在单个数据库上:
grant select on testdb.* to dba@localhost ; -- dba 可以查询 testdb 中的表。

grant 作用在单个数据表上:
grant select, insert, update, delete on testdb.orders to dba@localhost ;

grant 作用在表中的列上:
grant select(id, se, rank) on testdb.apache_log to dba@localhost ;

grant 作用在存储过程、函数上:
grant execute on procedure testdb.pr_add to 'dba'@'localhost'

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

六、查看 MySQL 用户权限 查看当前用户(自己)权限: show grants;

查看其他 MySQL 用户权限: show grants for dba@localhost;

七、撤销已经赋予给 MySQL 用户权限的权限

revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:

grant all on *.* to dba@localhost;

revoke all on *.* from dba@localhost;

八、MySQL grant、revoke 用户权限注意事项

grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。

如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 “grant option“

grant select on testdb.* to dba@localhost with grant option; 

这个特性一般用不到。实际中,数据库权限最好由 DBA 来统一管理。

来源地址:https://blog.csdn.net/qq_39740187/article/details/128780494

您可能感兴趣的文档:

--结束END--

本文标题: MySQL赋予用户的各种数据库操作权限

本文链接: https://www.lsjlt.com/news/384520.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • oracle怎么显示表的字段
    如何显示 oracle 表的字段 在 Oracle 数据库中,可以使用 DESC 命令显示表的字段。 语法: DESC table_name 参数: table_name:要显示字段的表...
    99+
    2024-05-14
    oracle
  • oracle怎么看所有的表
    在 oracle 数据库中查看所有表的步骤:连接到数据库运行查询:select table_name from user_tables; 如何使用 Oracle 查看所有表 ...
    99+
    2024-05-14
    oracle
  • oracle怎么显示行数
    如何使用 oracle 显示行数 在 Oracle 数据库中,有两种主要方法可以显示行数: 1. 使用 COUNT 函数 SELECT COUNT(*) FROM table_n...
    99+
    2024-05-14
    oracle
  • oracle怎么显示百分比
    oracle中显示百分比的方法有:使用百分号“%”;使用to_char()函数;使用format()函数(oracle 18c及更高版本);创建自定义函数。 Oracle 显...
    99+
    2024-05-14
    oracle
  • oracle怎么删除列
    oracle 中删除列的方法有两种:1)使用 alter table table_name drop column column_name 语句;2)使用 drop colum...
    99+
    2024-05-14
    oracle
  • sql怎么查看表的索引
    通过查询系统表,可以获取表的索引信息,包括索引名称、是否唯一、索引类型、索引列和行数。常用系统表有:mysql 的 information_schema.statistics、postg...
    99+
    2024-05-14
    mysql oracle
  • sql怎么查看索引
    您可以使用 sql 通过以下方法查看索引:show indexes 语句:显示表中定义的索引列表及其信息。explain 语句:显示查询计划,其中包含用于执行查询的索引。informat...
    99+
    2024-05-14
  • sql怎么查看存储过程
    如何查看 sql 存储过程的源代码:使用 show create procedure 语句直接获取创建脚本。查询 information_schema.routines 表的 routi...
    99+
    2024-05-14
  • sql怎么查看视图表
    要查看视图表,可以使用以下步骤:使用 select 语句获取视图中的数据。使用 desc 语句查看视图的架构。使用 explain 语句分析视图的执行计划。使用 dbms 提供...
    99+
    2024-05-14
    oracle python
  • sql怎么查看创建的视图
    可以通过sql查询查看已创建的视图,具体步骤包括:连接到数据库并执行查询select * from information_schema.views;查询结果将显示视图的名称、...
    99+
    2024-05-14
    mysql
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作