The CREATE USER statement creates new MySQL accounts.  To use it, you
must have the global CREATE USER privilege or the INSERT
privilege for the mysql database.
For each account, CREATE USER creates a new record in the
mysql.user table that has no privileges. An error occurs if the
account already exists.

The account can be given a password with the optional IDENTIFIED
BY clause.  The user value and the password are given the same way
as for the GRANT statement.  In particular, to specify the password
in plain text, omit the PASSWORD keyword. To specify the password
as the hashed value as returned by the PASSWORD() function, include
the keyword PASSWORD.
See also : [GRANT,  , GRANT].

The CREATE USER statement was added in MySQL 5.0.2.


  @subsubsection DROP USER Syntax



DROP USER user [, user] ...

The DROP USER statement deletes one or more MySQL accounts.
To use it, you
must have the global CREATE USER privilege or the DELETE
privilege for the mysql database.
Each account is named using the same format as for GRANT
or REVOKE; for example, 'jeffrey'@@'localhost'.  The user and
host parts of the account name correspond to the User and Host
column values of the user table record for the account.

DROP USER was added in MySQL 4.1.1 and originally removed only
accounts that have no privileges.  In MySQL 5.0.2, it was modified to also
remove account privileges.  This means that the procedure for removing an
account depends on your version of MySQL.

As of MySQL 5.0.2, remove an account and its privileges as follows:

DROP USER user;

The statement removes privilege records for the account from all grant tables.

From MySQL 4.1.1 to 5.0.1, DROP USER deletes only MySQL accounts that
don't have any privileges. In these MySQL versions, it serves only to remove
each account record from the user table. To remove a MySQL account, you
should use the following procedure, performing the steps in the order shown:

@enumerate
 --- Use SHOW GRANTS to determine what privileges the account has.
See also : [SHOW GRANTS,  , SHOW GRANTS].
 --- Use REVOKE to revoke the privileges displayed by SHOW GRANTS.
This removes records for the account from all the grant tables except the
user table, and revokes any global privileges listed in the user
table.
See also : [GRANT,  , GRANT].
 --- Delete the account by using DROP USER to remove the user table
record.
@end enumerate

DROP USER does not automatically close any open user sessions. Rather, in
the event that a user with an open session is dropped, the command does not take
effect until that user's session is closed. Once the session is closed, the user
is dropped, and that user's next attempt to log in will fail. This is by design.

Before MySQL 4.1.1, DROP USER is not available.  You should first
revoke the account privileges as just described. Then delete the user
table record and flush the grant tables like this:

mysql> DELETE FROM mysql.user
    -> WHERE User='user_name' and Host='host_name';
mysql> FLUSH PRIVILEGES;


  @subsubsection GRANT and REVOKE Syntax




GRANT priv_type [(column_list)] [, priv_type [(column_list)]] ...
    ON {tbl_name | * | *.* | db_name.*}
    TO user [IDENTIFIED BY [PASSWORD] 'password']
        [, user [IDENTIFIED BY [PASSWORD] 'password']] ...
    [REQUIRE
        NONE |
        [{SSL| X509}]
        [CIPHER 'cipher' [AND]]
        [ISSUER 'issuer' [AND]]
        [SUBJECT 'subject']]
    [WITH with_option [with_option] ...]

with_option =
    GRANT OPTION
  | MAX_QUERIES_PER_HOUR count
  | MAX_UPDATES_PER_HOUR count
  | MAX_CONNECTIONS_PER_HOUR count
  | MAX_USER_CONNECTIONS count

REVOKE priv_type [(column_list)] [, priv_type [(column_list)]] ...
    ON {tbl_name | * | *.* | db_name.*}
    FROM user [, user] ...

REVOKE ALL PRIVILEGES, GRANT OPTION FROM user [, user] ...


The GRANT and REVOKE statements allow system administrators to
create MySQL user accounts and to grant rights to and revoke them from
accounts.  GRANT and REVOKE are implemented in MySQL 3.22.11
or later. For earlier MySQL versions, these statements do nothing.

MySQL account information is stored in the tables of the mysql
database. This database and the access control system are discussed
extensively in [MySQL Database Administration], which you should consult
for additional details.

If the grant tables contain privilege records that contain mixed-case
database or table names and the lower_case_table_names system
variable is set, REVOKE cannot be used to revoke the privileges. It
will be necessary to manipulate the grant tables directly. (GRANT
will not create such records when lower_case_table_names is set,
but such records might have been created prior to setting the variable.)

Privileges can be granted at several levels:

   Global level
Global privileges apply to all databases on a given server. These privileges
are stored in the mysql.user table.
GRANT ALL ON *.* and
REVOKE ALL ON *.* grant and revoke only global privileges.

   Database level
Database privileges apply to all objects in a given database. These privileges
are stored in the mysql.db and mysql.host tables.
GRANT ALL ON db_name.* and
REVOKE ALL ON db_name.* grant and revoke only database privileges.

   Table level
Table privileges apply to all columns in a given table. These privileges are
stored in the mysql.tables_priv table.
GRANT ALL ON db_name.tbl_name and
REVOKE ALL ON db_name.tbl_name grant and revoke only table privileges.

   Column level
Column privileges apply to single columns in a given table. These privileges are
stored in the mysql.columns_priv table.
When using REVOKE, you must specify the same columns that were granted.

   Routine level
The CREATE ROUTINE, ALTER ROUTINE, EXECUTE, and
GRANT privileges apply to stored routines. They can be granted at the
global and database levels. Also, except for CREATE ROUTINE, these
privileges can be granted at the routine level for individual routines and
are stored in the mysql.procs_priv table.

  
