MySQL Grants
Luke Hebert
- 2 minutes read - 230 wordsManaging MySQL privileges is a routine part of database administration, and knowing the right GRANT syntax saves time when you need to adjust access for application users. Below is a compact reference for the two most common grant-related commands.
Viewing Current Grants
To see what privileges a specific user already holds, run SHOW GRANTS with the target account:
mysql> SHOW GRANTS FOR mywebnet_adm749@localhost;This returns a list of every privilege granted to that user, broken down by global, database, table, and routine level.
Applying New Grants
When you need to add privileges such as the ability to execute stored routines, alter routines, or create and view views, issue a GRANT statement:
mysql> GRANT EXECUTE, ALTER ROUTINE, CREATE VIEW, SHOW VIEW ON *.* TO mywebnet_adm749@localhost;Pressing ENTER executes the statement immediately. The ON *.* scope applies the privileges globally; narrow it to a specific database or table if the principle of least privilege calls for it.
Always follow a GRANT with FLUSH PRIVILEGES; if you are modifying the mysql system tables directly. For standard GRANT/REVOKE statements, MySQL updates the privilege tables automatically, so the flush is optional but harmless.
Quick Tips
- Use
REVOKEwith the same privilege list to remove access. - Run
SHOW GRANTSagain after any change to confirm the final state. - Keep a record of who holds which privileges; it makes audits and handoffs much smoother.