Introduction
Access control keeps data safe by letting only the right people see or change it.
Access control keeps data safe by letting only the right people see or change it.
GRANT privileges ON database.table TO 'user'@'host'; REVOKE privileges ON database.table FROM 'user'@'host';
GRANT SELECT ON mydb.customers TO 'alice'@'localhost';
REVOKE INSERT ON mydb.orders FROM 'bob'@'localhost';
GRANT ALL PRIVILEGES ON mydb.* TO 'carol'@'%';
This creates a database and table, grants read-only access to 'testuser', and shows the permissions.
CREATE DATABASE IF NOT EXISTS mydb; USE mydb; CREATE TABLE IF NOT EXISTS customers ( id INT PRIMARY KEY, name VARCHAR(50) ); GRANT SELECT ON mydb.customers TO 'testuser'@'localhost'; SHOW GRANTS FOR 'testuser'@'localhost';
Always give the least permissions needed to keep data safe.
Access control helps prevent mistakes and attacks on your data.
Access control limits who can see or change data.
Use GRANT and REVOKE to manage permissions.
Proper access control keeps data safe and trustworthy.
GRANT SELECT ON employees TO 'user1'@'localhost';
REVOKE INSERT ON employees FROM 'user1'@'localhost';employees table?GRANT SELECT ON sales TO 'user2'@'%';
REVOKE SELECT ON sales FROM 'user2'@'%';Pass the test and this pattern moves unknown