ps:通常我用的是:
1.“grant all on *.* to root@'%' identified by 'yourpassword';”——这个还可以顺带设置密码。
2.“flush privileges; ”——刷新一下,让权限生效。

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;

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修改数据库表权限的更多相关文章

  1. MySQL——修改数据库远程权限

    语句 赋予权限 ON *.*前一个*代表库后一个代表表 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxxx' WITH GRA ...

  2. MySQL中将数据库表名修改成大写的存储过程

    原文:MySQL中将数据库表名修改成大写的存储过程 MySQL中将数据库表名修改成大写的存储过程 创建存储过程的代码: DROP PROCEDURE IF EXISTS uppercaseTablen ...

  3. MySQL更改数据库表的存储引擎

    MySQL更改数据库表的存储引擎 1.查看表的原存储引擎 show create table user; 'user', 'CREATE TABLE `user` (\n `id` int(11) N ...

  4. MySQL修改数据表存储引擎的3种方法介绍

    这篇文章主要介绍了MySQL修改数据表存储引擎的3种方法介绍,分别是直接修改.导出导入.创建插入3种方法, 可以参考下   MySQL作为最常用的数据库,经常遇到各种各样的问题.今天要说的就是表存储引 ...

  5. MySQL查看数据库表容量大小

    本文介绍MySQL查看数据库表容量大小的命令语句,提供完整查询语句及实例,方便大家学习使用. 1.查看所有数据库容量大小 select table_schema as '数据库', sum(table ...

  6. Next Cloud通过修改数据库表,达到替换文件而不改变分享的链接地址的效果,以及自定义分享链接地址

    Next Cloud如何通过修改数据库表,达到替换文件而不改变分享的链接地址的效果,以及自定义分享的链接地址 本文首发于我的个人博客:https://chens.life/nextcloud-chan ...

  7. mysql修改数据库编码(数据库字符集)和表的字符编码的方法

    Mysql数据库是一个开源的数据库,应用非常广泛.以下是修改mysql数据库的字符编码的操作过程和将表的字符编码转换成utf-8的方法,需要的朋友可以参考下. mysql将表的字符编码转换成utf-8 ...

  8. MySQL修改数据库、表、列、外键字符编码和排序编码

    在重启Confluence应用时,突然遇见这个检查错误,查询总结需要修改Mysql数据库的所有字符编码和排序编码,报错如下: Confluence Help – This installation o ...

  9. mysql数据库连接状态,不要做修改数据库表结构的操作;数据库迁移操作;

    在开发过程中,python的flask框架使用sqlalmysql连接mysql数据库. 在程序连接数据量过程中,不要修改数据表的结构.比如在连接状态中使用下面的软件修改数据表结构,这个软件立即就会卡 ...

随机推荐

  1. springMVC+jpa配置之简单案例

    搭建springMVC+jpa的亲身经历,看着网上的博客,自己摸索着搭建框架结果错误一大堆.现在把流程走一遍,方便以后查看. 其中我遇到这样的一个问题:直接启动tomcat运行保存实体能通过,但是通过 ...

  2. TETRIS 项目开发笔记

    java学习一个月了,没有什么进展,期间又是复习Linux,又是看Android,瞻前顾后,感觉自己真的是贪得无厌, 学习的东西广而不精,所以写出的文章也就只能泛泛而谈.五一小长假,哪里都没有去,也不 ...

  3. SpringMvc中Interceptor拦截器用法

    SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理.比如通过它来进行权限验证,或者是来判断用户是否登陆等. 一. 使用场景 1 ...

  4. [Letcode] 1. Two Sum

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  5. 记录:asp.net mvc 中 使用 jquery 实现html5 实现placeholder 密码框 提示兼容password IE6

    @{ViewBag.Title = "完美结合";} <script>var G_start_time = new Date;</script> <! ...

  6. centos6.4 安装 hive 0.12.0

    环境:centos6.4  64bit, 前提:hadoop已经正常运行,可以使用hadoop dfsadmin -report查看 hive 解压   tar zcvf hive-0.12.0.ta ...

  7. 开启Objective-C --- OC基础知识

    一.Objective-C简述      Objective-C通常写作ObjC和较少用的Objective C或Obj-C,是扩充C的面向对象编程语言.Objective-C主要用于:编写iOS操作 ...

  8. iOS8 蓝牙设备的重连接(retrieve) Swift实现

    今天App写到了蓝牙重连的阶段,以前针对sdk 6.0写的代码,蓝牙设备的回复是通过 - (void)retrievePeripherals:(NSArray *)peripheralUUIDs 然后 ...

  9. Python - DICT 字典排序 - OrderedDict

    官方地址: https://docs.python.org/2/library/collections.html#collections.OrderedDict >>> # regu ...

  10. Jsp实现筛选并压缩文件批量下载

    Jsp实现筛选并压缩文件批量下载 首先明确一下需求,网页端点击一下button,传递特定的参数到download.jsp网页,筛选文件,对过滤得到的文件进行压缩,然后返回前端一个压缩包下载. 以下的代 ...