Specifications

The clauses in square brackets are optional. There are a number of placeholders in this syntax.
The first, privileges, should be a comma-separated list of privileges. MySQL has a defined
set of these. They are described in the next section.
The columns placeholder is optional. You can use it to specify privileges on a column-by-
column basis. You can use a single column name or a comma-separated list of column names.
The item placeholder is the database or table to which the new privileges apply.
You can grant privileges on all the databases by specifying *.* as the item. This is called
granting global privileges. You can also do this by specifying
* alone if you are not using any
particular database.
More commonly, you will specify all tables in a database as
dbname.*, on a single table as
dbname.tablename, or on specific columns by specifying dbname.tablename and some spe-
cific columns in the
columns placeholder. These represent the three other levels of privilege
available: database, table, and column, respectively. If you are using a specific database when
you issue this command, tablename on its own will be interpreted as a table in the current
database.
The user_name should be the name you want the user to log in as in MySQL. Remember that
it does not have to be the same as a system login name. The user_name in MySQL can also
contain a hostname. You can use this to differentiate between, say, laura (interpreted as
laura@localhost) and laura@somewhere.com. This is quite useful because users from differ-
ent domains often have the same name. It also increases security because you can specify
where users can connect from, and even which tables or databases they can access from a par-
ticular location.
The password should be the password you want the user to log in with. The usual rules for
selecting passwords apply. We will talk more about security later, but a password should not be
easily guessable. This means that a password should not be a dictionary word or the same as
the username. Ideally, it will contain a mixture of upper- and lowercase and nonalphabetic
characters.
The WITH GRANT OPTION option, if specified, allows the specified user to grant her own privi-
leges to others.
Privileges are stored in four system tables, in the database called mysql. These four tables are
called mysql.user, mysql.db, mysql.tables_priv, and mysql.columns_priv; they relate directly to
the four levels of privilege mentioned earlier. As an alternative to GRANT, you can alter these
tables directly. We will discuss this in more detail in Chapter 11, Advanced MySQL.
Creating Your Web Database
C
HAPTER 8
8
CREATING YOUR
WEB DATABASE
189
11 7842 CH08 3/6/01 3:38 PM Page 189