0
0
MySQLquery~5 mins

Granting privileges in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the GRANT statement in MySQL?
The GRANT statement is used to give users specific permissions to perform actions on databases, tables, or other objects in MySQL.
Click to reveal answer
beginner
How do you grant SELECT privilege on a database named 'shop' to a user 'alice'?
Use: <br>GRANT SELECT ON shop.* TO 'alice'@'localhost';
Click to reveal answer
intermediate
What does the ALL PRIVILEGES keyword mean in a GRANT statement?
ALL PRIVILEGES means the user gets all available permissions on the specified database or table, like SELECT, INSERT, UPDATE, DELETE, etc.
Click to reveal answer
intermediate
Why is it important to specify the host when granting privileges in MySQL?
Because MySQL users are identified by both username and host, specifying the host controls where the user can connect from, improving security.
Click to reveal answer
beginner
What command should you run after granting privileges to make sure they take effect immediately?
Run: FLUSH PRIVILEGES; to reload the privilege tables and apply changes immediately.
Click to reveal answer
Which command grants a user 'bob' permission to insert data into the 'employees' table?
AGRANT INSERT ON employees TO 'bob'@'localhost';
BGRANT INSERT ON database.* TO 'bob'@'localhost';
CGRANT INSERT ON employees.* TO 'bob'@'localhost';
DGRANT INSERT ON database.employees TO 'bob'@'localhost';
What does this command do? GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY 'pass';
ARevokes all privileges from 'admin'.
BGives 'admin' all permissions on all databases from any host.
CCreates a new database named 'admin'.
DGives 'admin' only SELECT permission on all databases.
Why might you use 'GRANT SELECT ON mydb.* TO 'user'@'localhost';' instead of 'GRANT SELECT ON mydb.* TO 'user'@'%';'?
ATo allow the user to connect only from the local machine for security.
BTo allow the user to connect from any machine.
CTo grant the user all privileges.
DTo revoke privileges from the user.
What is the effect of running 'FLUSH PRIVILEGES;' after a GRANT statement?
AIt backs up the privilege tables.
BIt deletes all user privileges.
CIt reloads the privilege tables so changes take effect immediately.
DIt restarts the MySQL server.
Which of these is NOT a valid privilege you can grant in MySQL?
AFLY
BINSERT
CSELECT
DUPDATE
Explain how to grant a user permission to read data from a specific database in MySQL.
Think about the syntax: GRANT SELECT ON database.* TO 'user'@'host';
You got /4 concepts.
    Describe why specifying the host is important when granting privileges in MySQL.
    MySQL treats 'user'@'localhost' and 'user'@'%' as different users.
    You got /3 concepts.