Access System
 
Tools for Setting Access Privileges
 

One can edit the tables of a database (assuming, of course, that you have the appropriate access privileges) with the usual SQL commands INSERT, UPDATE, and DELETE. However, that is a tiring and error-prone occupation. It is much more convenient to use the commands GRANT and REVOKE, which are the centerpiece of this section. Further alternatives for particular tasks are the MySQL tool mysqladmin and the Perl script mysql_setpermission.

 

Caution

 

MySQL maintains, for reasons of speed optimization, copies of the mysql tables in RAM. Direct changes to the tables are effective only if they are explicitly reread by MySQL via the SQL command FLUSH PRIVILEGES or the external program mysqladmin reload. (With GRANT and REVOKE this rereading takes place automatically.)

 

Changing Access Privileges with GRANT and REVOKE

 
The syntax of the GRANT and REVOKE commands, in simplified form, is as follows:
 
GRANT privileges
ON [database.]table
TO user@host [IDENTIFIED BY 'password']
[WITH GRANT OPTION]
REVOKE privileges
ON [database.]table
FROM user@host
 

If you wish to change the access privileges for all the tables of a database, the correct form to use is ON database.*. If you wish to alter global privileges, then specify ON *.*.Itis not allowed to use wild cards in database names.

 

For user you can specify '' to indicate all users on a particular computer (for example, ''@computername). On the other hand, for host you must use '%' (for example, username@'%').

 

Depending on their function, these commands change the mysql tables user, db, tables_priv, and columns_priv.(The host table remains untouched.)