Name

GRANT

Synopsis

GRANT privileges [(columns)][,  . . . ] ON database.table

TO 'user'*'host' [IDENTIFIED BY [PASSWORD] 'password'][,  . . . ]

[REQUIRE NONE|[{SSL|X509}]

[CIPHER 'cipher' [AND]]

[SUBJECT 'subject']]

[WITH [GRANT OPTION | MAX_QUERIES_PER_HOUR count |
                      MAX_UPDATES_PER_HOUR count |
                      MAX_CONNECTIONS_PER_HOUR count]]

Use this statement to create new MySQL users and to grant user privileges. Privileges can be global (apply to all databases on the server), database-specific, table-specific, or column-specific. User information is stored in the grant tables in the mysql database on the server. Global privileges are stored in the user table. Database-specific privileges are stored in the db table. Table privileges are in the tables_priv table and column privileges are in the columns_priv table. You can edit these tables directly with SQL statements, such as INSERT, UPDATE, and DROP, followed by a FLUSH PRIVILEGES statement to update the server's cache. However, it's recommended that you use the GRANT statement to create users and to grant privileges, and the REVOKE statement to revoke privileges.

In the syntax, the privileges to grant to a user are listed immediately after the GRANT keyword in a comma-separated list. Several privileges may be granted to a user. To give a user all simple user privileges, you can use the ALL keyword. Here is an example of how you can grant privileges to a user:

GRANT ALL PRIVILEGES ON *.* TO 'tina'@'localhost' IDENTIFIED BY 'muller' WITH GRANT OPTION; ...

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.