在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. sql server 备份与恢复系列四 大容量模式下的备份与还原

    一. 概述 在sql server 备份与恢复系列的第一篇里,有讲到大容量模式下备份与还原的相关知识.这篇重点来演示在大容量模式下常用的备份与还原模式“完整备份+差异备份+日志备份”. 在大容量恢复模 ...

  2. shell运算符与流程控制-2

    1.shell运算符 1.1.算数运算符 原生的bash不支持算数运算,可以通过其它方式实现例如expr. `expr a + b` #a b为数字,和运算符之间要有空格 #``不是单引号,为键盘上E ...

  3. CentOS7.0小随笔——指令基本操作(Part.B)

    一.文件与目录基本操作指令 touch命令 在Linux中,touch指令可以建立一个空文件 但如果创建的文件本身存在(指在同一目录下),则会修改文件最后的访问时间,并不会更改文件内的内容. 例:# ...

  4. 手写spring(简易版)

    本文版权归 远方的风lyh和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作,如有错误之处忘不吝批评指正! 理解Spring本质: 相信之前在使用spring的时候大家都配置web.x ...

  5. TOMCAT源码分析(转)

    前言:   本文是我阅读了TOMCAT源码后的一些心得. 主要是讲解TOMCAT的系统框架, 以及启动流程.若有错漏之处,敬请批评指教!建议:   毕竟TOMCAT的框架还是比较复杂的, 单是从文字上 ...

  6. [NewLife.XCode]数据模型文件

    NewLife.XCode是一个有10多年历史的开源数据中间件,由新生命团队(2002~2019)开发完成并维护至今,以下简称XCode. 整个系列教程会大量结合示例代码和运行日志来进行深入分析,蕴含 ...

  7. Spring-WebSocket 教程

    WebSocket 教程 概述 WebSocket 是什么? WebSocket 是一种网络通信协议.RFC6455 定义了它的通信标准. WebSocket 是 HTML5 开始提供的一种在单个 T ...

  8. webmagic 的 helloworld

    <dependency> <groupId>us.codecraft</groupId> <artifactId>webmagic-core</a ...

  9. centos7安装kafka_2.11

    1.下载 官网地址:http://kafka.apache.org/downloads.html 下载:wget https://www.apache.org/dyn/closer.cgi?path= ...

  10. Docker容器Tomcat部署war包

    在docker容器中使用tomcat部署war包主要包括四个步骤,创建tomcat容器.上传war包到容器.重启容器.访问应用. 1.创建tomcat容器 使用docker run  -d --nam ...