Creating and Selecting a Database
198
| Database |
+----------+
| mysql |
| test |
| tmp |
+----------+
The
mysql
database describes user access privileges. The
test
database often is available as a
workspace for users to try things out.
The list of databases displayed by the statement may be different on your machine;
SHOW DATABASES
does not show databases that you have no privileges for if you do not have the
SHOW DATABASES
privilege. See
Section 13.7.5.11, “
SHOW DATABASES
Syntax”
.
If the
test
database exists, try to access it:
mysql>
USE test
Database changed
USE
, like
QUIT
, does not require a semicolon. (You can terminate such statements with a semicolon
if you like; it does no harm.) The
USE
statement is special in another way, too: it must be given on a
single line.
You can use the
test
database (if you have access to it) for the examples that follow, but anything you
create in that database can be removed by anyone else with access to it. For this reason, you should
probably ask your MySQL administrator for permission to use a database of your own. Suppose that
you want to call yours
menagerie
. The administrator needs to execute a command like this:
mysql>
GRANT ALL ON menagerie.* TO 'your_mysql_name'@'your_client_host';
where
your_mysql_name
is the MySQL user name assigned to you and
your_client_host
is the
host from which you connect to the server.
3.3.1. Creating and Selecting a Database
If the administrator creates your database for you when setting up your permissions, you can begin
using it. Otherwise, you need to create it yourself:
mysql>
CREATE DATABASE menagerie;
Under Unix, database names are case sensitive (unlike SQL keywords), so you must always refer
to your database as
menagerie
, not as
Menagerie
,
MENAGERIE
, or some other variant. This is
also true for table names. (Under Windows, this restriction does not apply, although you must refer to
databases and tables using the same lettercase throughout a given query. However, for a variety of
reasons, the recommended best practice is always to use the same lettercase that was used when the
database was created.)
Note
If you get an error such as
ERROR 1044 (42000): Access denied
for user 'monty'@'localhost' to database 'menagerie'
when
attempting to create a database, this means that your user account does not
have the necessary privileges to do so. Discuss this with the administrator or
see
Section 6.2, “The MySQL Access Privilege System”
.
Creating a database does not select it for use; you must do that explicitly. To make
menagerie
the
current database, use this command:
mysql>
USE menagerie
Database changed
Your database needs to be created only once, but you must select it for use each time you begin a
mysql
session. You can do this by issuing a
USE
statement as shown in the example. Alternatively,
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...