CREATE DATABASE
Syntax
CREATE DATABASE
creates a database with the given name. To use this statement, you need the CREATE
privilege for the database. CREATE SCHEMA
is a synonym for CREATE DATABASE
.
An error occurs if the database exists and you did not specify IF NOT EXISTS
.
In MariaDB 5.6, CREATE DATABASE
is not permitted within a session that has an active LOCK TABLES
statement.
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. , "Character Set Support", discusses character set and collation names.
A database in MariaDB 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 creates only a directory under the MariaDB data directory and the db.opt
file. Rules for permissible database names are given in , "Schema Object Names". If a database name contains special characters, the name for the database directory contains encoded versions of those characters as described in , "Mapping of Identifiers to File 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 , "mysqladmin - Client for Administering a MariaDB Server".