w3resource

Steps to Remove Role from MySQL user


Revoke a Role from a User

Write a MySQL query to revoke the role "db_reader" from the user "alice".

Solution:

-- This command removes the 'db_reader' role from the user 'alice'
-- The revocation applies to connections from localhost
REVOKE 'db_reader' FROM 'alice'@'localhost';

Explanation:

  • Purpose of the Query:
    • The goal is to remove a previously assigned role from a user.
    • This demonstrates the REVOKE statement for role management.
  • Key Components:
    • REVOKE 'db_reader' : Specifies the role to be revoked.
    • FROM 'alice'@'localhost' : Identifies the user from whom the role is being removed.
  • Real-World Application:
    • Useful when a user's responsibilities change and they no longer require specific permissions.

Notes:

  • Confirm the role assignment exists before revoking it.

For more Practice: Solve these Related Problems:

  • Write a MySQL query to revoke the role "data_analyst" from "john_doe"@'localhost'.
  • Write a MySQL query to remove the role "db_admin" from "admin_user"@'%' after a change in responsibilities.
  • Write a MySQL query to revoke the role "app_user" from "app_dev"@'192.168.1.150' and confirm the removal.
  • Write a MySQL query to revoke the role "reporting_role" from both "user1"@'localhost' and "user2"@'localhost' simultaneously.


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous MySQL Exercise: Grant a Role to a User.
Next MySQL Exercise: Change a User's Password.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.