Database Reference
In-Depth Information
connect to the server from a host named
myhost.example.com
, the statements look like
this:
mysql>
CREATE USER 'cbuser'@'myhost.example.com' IDENTIFIED BY 'cbpass';
mysql>
GRANT ALL ON cookbook.* TO 'cbuser'@'myhost.example.com';
It may have occurred to you that there's a paradox in the procedure just described: to
set up a
cbuser
account that can connect to the MySQL server, you must first connect
to the server so that you can execute the
CREATE
USER
and
GRANT
statements. I'm as‐
suming that you can already connect as the MySQL
root
user because
CREATE
USER
and
GRANT
can be used only by a user such as
root
that has the administrative privileges
needed to set up other user accounts. If you can't connect to the server as
root
, ask your
MySQL administrator to create the
cbuser
account for you.
MySQL Accounts and Login Accounts
MySQL accounts differ from login accounts for your operating system. For example,
the MySQL
root
user and the Unix
root
user are separate and have nothing to do with
each other, even though the username is the same in each case. This means they very
likely have different passwords. It also means you don't create new MySQL accounts by
creating login accounts for your operating system; use
CREATE
USER
and
GRANT
instead.
After creating the
cbuser
account, verify that you can use it to connect to the MySQL
server. From the host that was named in the
CREATE
USER
statement, run the following
command to do this (the host named after
-h
should be the host where the MySQL
server is running):
%
mysql -h localhost -u cbuser -p
Enter password:
cbpass
Now you can proceed to create the
cookbook
database and tables within it, as described
in
Recipe 1.2
. To make it easier to invoke
mysql
without specifying connection param‐
eters each time, put them in an option file (see
Recipe 1.4
).
See Also
For additional information about administering MySQL accounts, see
Chapter 23
.
1.2. Creating a Database and a Sample Table
Problem
You want to create a database and set up tables within it.