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 权限,分别可以作用在多个层次上。

1. grant 作用在整个 MySQL 服务器上:

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

2. grant 作用在单个数据库上:

grant select on testdb.* to dba@localhost; -- dba 可以查询 testdb 中的表。

3. grant 作用在单个数据表上:

grant select, insert, update, delete on testdb.orders to dba@localhost;

这里在给一个用户授权多张表时,可以多次执行以上语句。例如:

grant select(user_id,username) on smp.users to mo_user@'%' identified by '123345';
grant select on smp.mo_sms to mo_user@'%' identified by '123345';

4. grant 作用在表中的列上:

grant select(id, se, rank) on testdb.apache_log to dba@localhost;

5. 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 用户权限注意事项

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

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

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

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

十六、MySQL授权命令grant的使用方法的更多相关文章

  1. MySQL授权命令grant的使用方法

    本文实例,运行于 MySQL 5.0 及以上版本. MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删 ...

  2. MySQL授权命令grant的详细使用方法

    2019-01-07 转自 https://www.cnblogs.com/crxis/p/7044582.html 本文实例,运行于 MySQL 5.0 及以上版本. MySQL 赋予用户权限命令的 ...

  3. mysql进阶(二十六)MySQL 索引类型(初学者必看)

    mysql进阶(二十六)MySQL 索引类型(初学者必看)   索引是快速搜索的关键.MySQL 索引的建立对于 MySQL 的高效运行是很重要的.下面介绍几种常见的 MySQL 索引类型.   在数 ...

  4. mysql source命令超大文件导入方法总结

    本文章来给各位朋友介绍利用mysql source命令超大文件导入方法总结,下面收集了两种解决办法,一种是把数据库分文件导出然后再导入,另一种是修改my.ini配置文件,下面我一一给各位朋友介绍. 导 ...

  5. mysql 授权命令

    MySQL 数据库赋予用户权限操作表   MySQL清空数据库的操作:truncate table tablename; MySQL 赋予用户权限命令的简单格式可概括为:grant 权限 on 数据库 ...

  6. MySQL授权--WITH GRANT OPTION

    今天在学习MySQL的时候,看到一句描述 WITH GRANT OPTION should be left out if the user need not be able to grant othe ...

  7. Python学习日记(三十六) Mysql数据库篇 四

    MySQL作业分析 五张表的增删改查: 完成所有表的关系创建 创建教师表(tid为这张表教师ID,tname为这张表教师的姓名) create table teacherTable( tid int ...

  8. Linux命令(二十六) 用户管理命令

    一.添加用户 useradd useradd 命令用于创建新用户,格式为useradd [选项] 用户名. 可以使用 useradd 命令创建用户帐户,使用该命令创建账户时,默认的用户目录在 /hom ...

  9. Appium+python自动化(十六)- ADB命令,知否知否,应是必知必会(超详解)

    简介 Android 调试桥(adb)是多种用途的工具,该工具可以帮助你你管理设备或模拟器 的状态. adb ( Android Debug Bridge)是一个通用命令行工具,其允许您与模拟器实例或 ...

随机推荐

  1. 基于mkv31芯片ADC差分应用

    一.单端.全差分.伪差分 此部分转载https://www.cnblogs.com/alifpga/p/7976531.html 单端信号: 单端信号(single-end)是相对于差分信号而言的,单 ...

  2. 初学JavaScript正则表达式(八)

    JavaScript正则贪婪模式与非贪婪模式 贪婪模式: 例: \d{3,6} 匹配数字3到6次(正则表达式默认为贪婪模式,即匹配最多次,失败即停) '12345678'.replace(/\d{3, ...

  3. layer之关闭弹窗

    一. layer关闭弹出层方法1-1) 先获取某个弹出层的 index var index = layer.open();   var index = layer.alert(); var index ...

  4. jenkins配置自动部署java程序

    任务背景 该项目包含4个程序包:a.jar,b.jar,c.jar,d.jar,每次启动前需要修改程序中的配置文件(修改数据源配置),然后按照先后顺序启动. 任务目标 1.利用jenkins拉取代码, ...

  5. VS2017 Thrift编译出的Release版本的库调用报错LNK2001

    在使用thrift的过程中, 当我使用完thrift debug版本编译出来的库调试完成后, 改成release版本的时候, 就出现了如下错误, 莫名其妙啊, 同一套代码, 那只能是编译库的时候设置和 ...

  6. Git修改和配置用户名和邮箱

    git在push/push to时需要使用到user.name和user.email,切记一定要现配置好查看user.name/user.email git config user.name git ...

  7. gradle 多模块Springboot项目 compile project引用其他模块的坑

    本来以为子项目中compile project(':xxx'),就能引用其他模块了,因为之后idea也没在引用时候标红 然而我gradle build的时候,居然各种找不到引用模块的类 最后在stac ...

  8. mybatis错误:There is no getter for property named 'delegate' in 'class com.sun.proxy.$Proxy某某'

    错误描述: There is no getter for property named 'delegate' in 'class com.sun.proxy.$Proxy32' 错误原因: 1.你有多 ...

  9. Excel 快捷键

    自从转岗为项目经理之后,Excel的使用频率大大的增加了,所以需要有意识的学习一下快捷键,提升自己的动作效率. 如下实在Microsoft 官网找到的资料,记录下,以作后备查看: 一.通过键盘访问功能 ...

  10. 也作一下装配脑袋的Expression习题【转】

    一.习题 http://www.cnblogs.com/Ninputer/archive/2009/08/28/expression_tree1.html 二.参考 http://msdn.micro ...