在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> 

转载于:https://www.cnblogs.com/kerrycode/p/7421777.html

MySQL 授予普通用户PROCESS权限相关推荐

  1. Mysql数据库给用户添加权限

    1.Mysql下创建新的用户 新创建的用户默认是没有任何权限的. 语法格式: create user 用户名 identified by '密码'; 2.给用户分配权限 语法结构: grant 权限 ...

  2. MySql:从任何主机授予根用户登录权限

    Note that this is Not very secure, and should only be used for a local development box where you don ...

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

    2019独角兽企业重金招聘Python工程师标准>>> 1.新建用户 //登录MYSQL @>mysql -u root -p @>密码 //创建用户 mysql> ...

  4. MySQL为其他用户创建数据库_MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限...

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

  5. mysql新用户不能创建数据库中_MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限...

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

  6. MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限(转)

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

  7. mysql - user/privileges/用户与权限/用户权限/管理用户权限

    目录 1.用户权限有哪些 2.用户权限操作语句 3.授权说明与授权原则 1.用户权限有哪些 总共28个权限 mysql数据库中的3个权限表:user .db. host 权限表的存取过程是: 1)先从 ...

  8. MySQL查看所有用户及权限

    查看MYSQL数据库中所有用户 及 有权访问的host mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS ...

  9. mysql 赋给用户表权限

    语法:  grant all privileges on *.* to joe@localhost identified by '1'; flush privileges; 拿  joe    1 登 ...

最新文章

  1. 人工智能如何落地安防?需先迈过算力这一关
  2. 青藏高原地下巨型空间形成原因
  3. 文巾解题 595. 大的国家
  4. docker修改镜像的存储位置_Docker存储原理
  5. JS 将有规律的数组,转换成对象数组
  6. 二项式定理的几何视觉演示再次来袭,这次你看懂了吗?
  7. Kafka的Spring Cloud Stream
  8. 多目标跟踪全解析,全网最全
  9. 51Nod-1051 最大子矩阵和【最大子段和+DP】
  10. IDENT_CURRENT ,@@identity,SCOPE_IDENTITY() 之间对比
  11. (2016弱校联盟十一专场10.2) E.Coins
  12. phalapi做登录检测_1.4 PhalApi 2.x 接口响应与在线调试
  13. 21年,周杰伦越发孤独
  14. Linux下mongodb用户管理和设置远程登陆
  15. (亲测)躺着破解IDM下载权限,治疗不用破解补丁的强迫症们
  16. RFID 有源,半源和无源的区别
  17. Java类加载的加载,验证,准备,解析,初始化小结
  18. icp许可证年检办理什么企业需要办理
  19. linux wps2016_2016年十大Linux新闻报道
  20. Towards Spatio-Temporal Aware Traffic Time Series Forecasting

热门文章

  1. mysql binlog备份_MySQL mysqldump + mysqlbinlog 备份和还原
  2. mybatis plus使用in查询
  3. Java语言 List 和 Array 相互转换
  4. html5好看的大方框,这个样式导致HTML5的视频中的按钮变成一个方框。求解决…...
  5. [python机器学习及实践(2)]Sklearn实现朴素贝叶斯
  6. bitcoin转账api,python2.7
  7. (12)自定义数据流(实战Docker事件推送的REST API)——响应式Spring的道法术器...
  8. 剑指offer58 二叉树的下一个结点
  9. 从安装认识Angular 2
  10. 关于stm32的正交解码