GRANT assigns specific database privileges to MySQL users or roles, controlling what operations they can perform.
GRANT lets you specify exactly which databases, tables, or columns a MySQL user can read, write, or administer. It writes these rules to the mysql.user and related privilege tables.
You can grant global, database, table, column, or routine-level privileges such as SELECT, INSERT, UPDATE, DELETE, EXECUTE, and administrative rights like CREATE USER or RELOAD.
Use GRANT with ON and TO clauses. Always follow with FLUSH PRIVILEGES on older MySQL (<5.7) if you modify privilege tables directly.
GRANT SELECT ON ecommerce.Products TO 'analytics'@'%' IDENTIFIED BY 'S3cure!';
This lets the analytics user query, but not change, product records from any host.
List privileges comma-separated.GRANT SELECT, INSERT, UPDATE ON ecommerce.Orders TO 'ops'@'localhost';
Use the *.*
or db_name.*
wildcard.GRANT ALL PRIVILEGES ON ecommerce.* TO 'admin'@'%';
Run REVOKE or GRANT with new privileges. MySQL updates immediately; no restart needed.
Grant least privilege, use roles in MySQL 8.0+, and store credentials in a secrets manager. Always use strong passwords or auth plugins.
Mixing GRANT with manually editing privilege tables can create inconsistency—always use GRANT/REVOKE. Forgetting WITH GRANT OPTION
prevents a user from passing rights along—add it only when necessary.
Yes. Add IDENTIFIED BY 'pwd' in the GRANT statement. MySQL creates the user automatically.
No for GRANT/REVOKE. Only needed if you manually edit the privilege tables.
Execute SHOW GRANTS FOR 'user'@'host'; The server returns the GRANT statements that define current rights.