在MySQL中如何给普通用户授予查看所有用户线程/连接的权限,当然,默认情况下show processlist是可以查看当前用户的线程/连接的。

mysql> grant process on MyDB.* to test;

ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES

第一次授予这样的权限,错误原因是process权限是一个全局权限,不可以指定在某一个库上(个人测试库为MyDB),所以,把授权语句更改为如下即可:

mysql> grant process on *.* to test;

Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

如果不给拥有授予PROESS权限 ,show processlist命令只能看到当前用户的线程,而授予了PROCESS权限后,使用show  processlist就能看到所有用户的线程。官方文档的介绍如下:

SHOW PROCESSLIST shows you which threads are running. You can also get this information from the INFORMATION_SCHEMA PROCESSLIST table or the mysqladmin processlist command. If you have the PROCESS privilege, you can see all threads. Otherwise, you can see only your own threads (that is, threads associated with the MySQL account that you are using). If you do not use the FULL keyword, only the first 100 characters of each statement are shown in the Info field.

我们先创建下面账号test2,然后测试如下:

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> grant select,insert,update,delete on MyDB.* to test2@'%' identified by 'test2';

Query OK, 0 rows affected (0.00 sec)

 

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

mysql> select user();

+-----------------+

| user()          |

+-----------------+

| test2@localhost |

+-----------------+

1 row in set (0.00 sec)

 

mysql> show processlist;

+----+-------+-----------+------+---------+------+-------+------------------+

| Id | User  | Host      | db   | Command | Time | State | Info             |

+----+-------+-----------+------+---------+------+-------+------------------+

| 25 | test2 | localhost | NULL | Query   |    0 | init  | show processlist |

+----+-------+-----------+------+---------+------+-------+------------------+

1 row in set (0.00 sec)

 

mysql> show full processlist;

+----+-------+-----------+------+---------+------+-------+-----------------------+

| Id | User  | Host      | db   | Command | Time | State | Info                  |

+----+-------+-----------+------+---------+------+-------+-----------------------+

| 25 | test2 | localhost | NULL | Query   |    0 | init  | show full processlist |

+----+-------+-----------+------+---------+------+-------+-----------------------+

1 row in set (0.01 sec)

 

mysql> 

然后我们给用户test2授予process权限, 如下所示,再测试show processlist 就能看到所有用户的线程/连接信息(如果是之前已经建立连接的会话,必须退出重新登录,否则依然只能看到当前用户的线程。)

mysql> grant process on *.* to test2;

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> show processlist;

+----+-------+-----------+------+---------+------+-------+------------------+

| Id | User  | Host      | db   | Command | Time | State | Info             |

+----+-------+-----------+------+---------+------+-------+------------------+

| 19 | root  | localhost | NULL | Sleep   |   16 |       | NULL             |

| 22 | test  | localhost | MyDB | Sleep   |  738 |       | NULL             |

| 24 | test  | localhost | NULL | Sleep   |  692 |       | NULL             |

| 25 | test2 | localhost | NULL | Sleep   |  531 |       | NULL             |

| 27 | test2 | localhost | NULL | Query   |    0 | init  | show processlist |

+----+-------+-----------+------+---------+------+-------+------------------+

5 rows in set (0.00 sec)

 

mysql> 

The PROCESS privilege pertains to display of information about the threads executing within the server (that is, information about the statements being executed by sessions). The privilege enables use of SHOW PROCESSLIST or mysqladmin processlist to see threads belonging to other accounts; you can always see your own threads. The PROCESS privilege also enables use of SHOW ENGINE.

如上官方文档所说,如果给用户授予了PROCESS权限, 那么用户就拥有了使用SHOW ENGINES命令的权限,如下所示:

mysql> select user();

+----------------+

| user()         |

+----------------+

| test@localhost |

+----------------+

1 row in set (0.00 sec)

 

mysql> show engines;

+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+

| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |

+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+

| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |

| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |

| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |

| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |

| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |

| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |

| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |

| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |

| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |

+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+

9 rows in set (0.00 sec)

 

mysql> 

MySQL 授予普通用户PROCESS权限的更多相关文章

  1. MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限

    1.新建用户 //登录MYSQL @>mysql -u root -p @>密码 //创建用户 mysql> insert into mysql.user(Host,User,Pas ...

  2. mysql 新增 删除用户和权限分配

    请一定安此步骤来创建新的用户. 1. 新增用户 mysql>insert into mysql.user(Host,User,Password) values("localhost&q ...

  3. MySQL 之迁移用户及权限

    参考来源: https://www.cnblogs.com/huangmr0811/p/5570994.html https://blog.csdn.net/u011665746/article/de ...

  4. mysql 赋给用户远程权限 grant all privileges on

    我配置了权限 就可以在Windows下访问我虚拟机中的数据库了 来源:http://blog.csdn.net/louisliaoxh/article/details/52767209 登录: 在本机 ...

  5. MySQL中创建用户分配权限

    测试环境:CentOS6.8 和 MySQL5.5.4 一 需求 在项目开发的过程中可能需要开放自己的数据库给别人,但是出于安全的考虑,不能同时开放自己服务器里的其他数据库.那么可以新建一个用户,赋予 ...

  6. MySQL操作(一)用户及权限

    一.mysql 里的所有用户都是存储在数据库mysql的user表里 二.创建普通用户.赋权.撤销权限 的操作 1.创建用户(需要先用root进去mysql)格式:create  user  '用户名 ...

  7. MySQL授权远程用户登录权限

    1 举例子,建数据库,然后 赋予用户远程访问的所有权限,最后刷新权限 create database cmf DEFAULT CHARACTER SET utf8; grant all on cmf. ...

  8. mysql新加用户设置权限

    1.开通操作权限和表权限 GRANT CREATE,ALTER,DROP,INSERT,UPDATE,DELETE,SELECT ON interface.* TO test1@'%' identif ...

  9. linux中授予普通用户root权限

    本来也更改了/etc/passwd,改成0:0淡水其他地方又出问题,所以又改回来了. chown -R hxsyl .Spark_Relvant 当前在hadoop-2.6.4下,‘.’表示当前目录.

随机推荐

  1. Linux编程 24 shell编程(结构化 if [ condition ] 数值比较,字符串比较)

    一.概述 接着上篇讲的结构化命令,最后讲到了test命令的另一种写法 if [ condition ],它的语法格式如下: --格式如下: if [ condition ] then commands ...

  2. 从Java小白到收获BAT等offer,分享我这两年的经验和感悟

    微信公众号[程序员江湖] 作者黄小斜,斜杠青年,某985硕士,阿里 Java 研发工程师,于 2018 年秋招拿到 BAT 头条.网易.滴滴等 8 个大厂 offer,目前致力于分享这几年的学习经验. ...

  3. XSS和CSRF

    说到XSS这个问题,XSS又叫跨站请求攻击,大意是说比如我发表了一篇博客,然后我在自己博客里面插入了一段恶意的js脚本代码,这段代码用于获取当前用户的cookie,并发送到我的服务器,当你们在看到这篇 ...

  4. AspNetPager分页控件的使用方法

    1. 首先将AspNetPager.dll复制于应用程序下的bin目录,打开解决方案,引入dll文件 (通过NuGet获取) 2. 在工具栏中添加控件,这样可以支持拖拽使用 3.页面拖入分页控件,设置 ...

  5. .Net程序员学用Oracle系列(19):导出、导入(备份、还原)

    1.传统的导出/导入工具 1.1.EXP 命令详解 1.2.IMP 命令详解 1.3.EXP/IMP 使用技巧 2.新的导出/导入工具 2.1.EXPDP/IMPDP 参数说明 2.2.EXPDP/I ...

  6. 简单快速的让你的json解析速度快上加快

    背景 最近小编在做公司的一个需求.要求是把系统内的一些大型文本文件上传到第三方那里,而且第三方要求的交互数据的方式是采用post请求发送json串的形式进行的. 问题 做到中途才发现问题,由于单个文本 ...

  7. JQ-bootstrap我的开源前端框架

        因为实在不知道写啥,所以迟迟没有相关的介绍.但是必须要积累过程资产,所以还是介绍一下,不定哪天就有人用了.       首先还是介绍遇到的问题,我是做传统后台管理系统的,公司赶时髦,要用boo ...

  8. java 8 双冒号运算符

    前言 java8增加了双冒号运算符.lambda本质上都是语法糖,学习过C#委托.匿名委托再理解java8中的双冒号运算符就容易多了.双冒号就是把方法当作参数传递给需要的方法,或者说是传递到strea ...

  9. R语言实战(一)——基础入门

    从今天开始接触R语言,主要参考的书籍是<R语言实战>. 1.安装R语言程序 Windows:http://mirror.bjtu.edu.cn/cran/ Linux:apt-get in ...

  10. SQL语句NOT IN优化之换用NOT EXISTS

    NOT IN查询示例(示例背景描述:根据条件查询Questions表得到的数据基本在PostedData表中不存在,为完全保证查询结果在PostedData表中不存在,使用NOT IN): SET S ...