CREATE DATABASE [IF NOT EXISTS]db_name
[create_specification
] ...create_specification
: [DEFAULT] CHARACTER SET [=]charset_name
| [DEFAULT] COLLATE [=]collation_name
CREATE DATABASE
creates a database
with the given name. To use this statement, you need the
CREATE
privilege for the database.
An error occurs if the database exists and you did not specify
IF NOT EXISTS
.
As of MySQL 4.1.1, create_specification
options specify database characteristics. Database characteristics
are stored in the db.opt
file in the database
directory. The CHARACTER SET
clause specifies
the default database character set. The COLLATE
clause specifies the default database collation.
Section 9.1, “Character Set Support”, discusses character set and collation
names.
A database in MySQL is implemented as a directory containing files
that correspond to tables in the database. Because there are no
tables in a database when it is initially created, the
CREATE DATABASE
statement only
creates a directory under the MySQL data directory (and the
db.opt
file, for MySQL 4.1.1 and up). Rules
for allowable database names are given in
Section 8.2, “Database, Table, Index, Column, and Alias Names”.
If you manually create a directory under the data directory (for
example, with mkdir), the server considers it a
database directory and it shows up in the output of
SHOW DATABASES
.
You can also use the mysqladmin program to create databases. See Section 4.5.2, “mysqladmin — Client for Administering a MySQL Server”.
User Comments
Add your own comment.