MySQL 授予普通用户PROCESS权限

在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 [email protected]‘%‘ 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()          |
+-----------------+
| [email protected] |
+-----------------+
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()         |
+----------------+
| [email protected] |
+----------------+
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> 
时间: 2024-10-01 07:44:55

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

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

1.新建用户 //登录MYSQL@>mysql -u root -p@>密码//创建用户mysql> insert into mysql.user(Host,User,Password) values('localhost','jeecn',password('jeecn'));//刷新系统权限表mysql>flush privileges;这样就创建了一个名为:jeecn  密码为:jeecn  的用户. //退出后登录一下mysql>exit;@>mysql -u

MySQL创建数据库用户、权限设置

创建数据库用户 添加权限 类别 详细解示 基本语法 grant 权限 on 库.表 to '用户'@'主机' identified by '密码'; 示例 grant select, insert on test.* to 'liwenkai'@'localhost' identified by '4311'; 示例说明 给予liwenkai用户,在本机连接test库所有表的权限.操作的这些表具有查询和写入权限 注:可以针对一个用户增加多条权限. 删除权限 类别 详细解示 基本语法 revoke

MySQL如何新增用户(权限),改密码,删除用户

查看MYSQL数据库中所有用户mysql>use mysql;mysql>select host, user from user;或者mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;查看数据库中具体某个用户的权限mysql>show grants for [email protected]: 1.使用 root 管理员登陆 mysqlmysql -u

MySQL中创建用户分配权限

测试环境:CentOS6.8 和 MySQL5.5.4 一 需求 在项目开发的过程中可能需要开放自己的数据库给别人,但是出于安全的考虑,不能同时开放自己服务器里的其他数据库.那么可以新建一个用户,赋予该用户特定的数据库权限. 二 实现 1 新建用户 // root 用户登陆 MySQL mysql -uroot -p Enter password: // 新建用户 mysql>insert into mysql.user(Host,User,Password) values("localh

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

我配置了权限 就可以在Windows下访问我虚拟机中的数据库了 来源:http://blog.csdn.net/louisliaoxh/article/details/52767209 登录: 在本机上使用命令行登录,并切换到MySQL库 mysql -uroot -p use mysql(省略了一些内容的,新手不要效仿) 更改表 要查看user表中user='root'的对应情况,根据实际需求来更改表信息 select host,user from user where user='root'

允许mysql远程连接 ,用户数据库权限

1. 改表法.可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%" mysql -u root -pvmwaremysql>use mysql;mysql>update user set host = '%' where

mysql 赋给用户远程权限

更改权限 使用grant all privileges on来更改用户对应某些库的远程权限 语法模板 grant all privileges on 库名.表名 to '用户名'@'IP地址' identified by '密码' with grant option;flush privileges; 注: 库名:要远程访问的数据库名称,所有的数据库使用"" 表名:要远程访问的数据库下的表的名称,所有的表使用"" 用户名:要赋给远程访问权限的用户名称 IP地址:可以

mysql 查看用户的权限

show grants for 'username'@'%';

linux中授予普通用户root权限

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