13.1.3. CREATE DATABASE
Syntax
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
[create_specification
[, create_specification
] ...]
create_specification
:
[DEFAULT] CHARACTER SET charset_name
| [DEFAULT] COLLATE collation_name
CREATE DATABASE
creates a database with the
given name. To use CREATE DATABASE
, you need
the CREATE
privilege on the database.
CREATE SCHEMA
is a synonym for
CREATE DATABASE
.
Rules for allowable database names are given in
Section 9.2, “Database, Table, Index, Column, and Alias Names”. An error occurs if the database
exists and you did not specify IF NOT EXISTS
.
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.
Chapter 10, Character Set Support, discusses character set and collation
names.
Databases in MySQL are implemented as directories 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 creates only a
directory under the MySQL data directory and the
db.opt
file.
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 8.7, “mysqladmin — Client for Administering a MySQL Server”.