In MySQL, even if the user has onlySELECT
Permissions can still be executedSHOW PROCESSLIST
andKILL
Order. The reasons are as follows:
1. SHOW PROCESSLIST No special permissions are required
-
By default, any user can execute
SHOW PROCESSLIST
, even if onlyUSAGE
Permissions (minimum permissions). - But if MySQL is enabled
--skip-show-database
Startup option, ordinary users may not see processes that do not belong to them.
2. KILL command permission dependency
-
KILL
The execution permission of the command depends onPROCESS
orSUPER
Permissions:- If the user has
PROCESS
Permissions, canKILL
Your own conversation(i.e., the connection you made yourself). - If the user has
SUPER
Permissions, canKILL
Any conversation(including sessions of other users).
- If the user has
-
Even if only granted
SELECT
Permissions, users can stillKILL
Your own conversation:- existMySQL 5.7+, if the user has
CONNECTION_ADMIN
(orSUPER
A substitute for permissions), it may still beKILL
Session. - existMySQL 8.0+, introduces more fine-grained permission control, but by default, some operations may still allow
KILL
。
- existMySQL 5.7+, if the user has
3. Why can users with SELECT permissions KILL?
-
Possible reasons:
-
User implicitly owned
PROCESS
Permissions(examinetable confirmation).
-
Version differences of MySQL(Some versions allow by default
KILL
Own conversation). -
The user belongs to a role (MySQL 8.0+), the role may be awarded
PROCESS
orKILL
Permissions.
-
User implicitly owned
How to completely ban users from executing KILL?
Method 1: Clearly revoke PROCESS and SUPER permissions
REVOKE PROCESS, SUPER ON *.* FROM 'query'@'%'; FLUSH PRIVILEGES;
- This way users can only
SHOW PROCESSLIST
, but notKILL
Any session (including your own).
Method 2: Limit SHOW PROCESSLIST (optional)
If you want the user to see the process list at all:
REVOKE PROCESS ON *.* FROM 'query'@'%'; FLUSH PRIVILEGES;
- so
SHOW PROCESSLIST
Only display the user's own sessions (not all sessions).
Method 3: Use MySQL 8.0+ fine-grained permissions
In MySQL 8.0+, more precise control can be achieved:
-- prohibit KILL Other sessions REVOKE SYSTEM_USER, SYSTEM_VARIABLES_ADMIN, SESSION_VARIABLES_ADMIN ON *.* FROM 'query'@'%'; -- Make sure there is no PROCESS Permissions REVOKE PROCESS ON *.* FROM 'query'@'%'; FLUSH PRIVILEGES;
Verify user permissions
-- View user permissions SHOW GRANTS FOR 'query'@'%'; -- examine PROCESS Permissions SELECT * FROM WHERE user='query'\G
- if
Process_priv = 'Y'
, indicating that the user hasPROCESS
Permissions, canKILL
Own conversation.
Summarize
-
SELECT
Permissions themselves will not be allowedKILL
,butPROCESS
Permissions。 -
To prohibit
KILL
, it must be clearly revokedPROCESS
andSUPER
Permissions。 -
MySQL 8.0+ provides finer granular permission control, can be more stringently restricted
KILL
operate.
If yourquery
Users canKILL
, please check its full permissions (there may be hiddenPROCESS
or role permissions).
The above is the detailed content of the solution to MySQL completely prohibits users from executing KILL. For more information about MySQL prohibiting users from executing KILL, please pay attention to my other related articles!