w3resource

Database access Grant for bob on InventoryDB


Grant Privileges on a Specific Database

Write a MySQL query to grant all privileges on the "InventoryDB" database to the user "bob".

Solution:

-- This command gives the user 'bob' full control over the InventoryDB database
-- Grants all possible privileges on all tables in InventoryDB for localhost connections
GRANT ALL PRIVILEGES ON InventoryDB.* TO 'bob'@'localhost'; 

Explanation:

  • Purpose of the Query:
    • The goal is to provide the user "bob" with comprehensive access to the InventoryDB database.
    • This demonstrates how to assign privileges on a database-specific basis.
  • Key Components:
    • GRANT ALL PRIVILEGES : Specifies that every privilege is granted.
    • ON InventoryDB.* : Targets all tables within the InventoryDB database.
    • TO 'bob'@'localhost' : Identifies the recipient user.
  • Real-World Application:
    • Ideal for administrative users who need full control over a specific database.

Notes:

  • Granting all privileges should be done cautiously to prevent security risks.

For more Practice: Solve these Related Problems:

  • Write a MySQL query to grant all privileges on the "InventoryDB" database to the user "bob" for connections from any host.
  • Write a MySQL query to grant all privileges on "InventoryDB" to "bob" but restrict privileges only to DML operations.
  • Write a MySQL query to grant all privileges on "InventoryDB" to "bob" while excluding access to a specific table named "InventoryDB.secret".
  • Write a MySQL query to grant all privileges on "InventoryDB" to "bob" and then verify the changes by querying the system privileges table.


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

Previous MySQL Exercise: Flush Privileges.
Next MySQL Exercise: Grant Read-Only Privileges.

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.