Documentation Home
MySQL 9.3 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 261.1Kb
Man Pages (Zip) - 368.3Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.3 Reference Manual  / ...  / SQL Statements  / Data Definition Statements  /  CREATE DATABASE Statement

15.1.13 CREATE DATABASE Statement

CREATE {DATABASE | SCHEMA} [IF NOT EXISTS]db_name    [create_option] ...create_option: [DEFAULT] {    CHARACTER SET [=]charset_name  | COLLATE [=]collation_name  | ENCRYPTION [=] {'Y' | 'N'}}

CREATE DATABASE creates a database with the given name. To use this statement, you need theCREATE privilege for the database.CREATE SCHEMA is a synonym forCREATE DATABASE.

An error occurs if the database exists and you did not specifyIF NOT EXISTS.

CREATE DATABASE is not permitted within a session that has an activeLOCK TABLES statement.

Eachcreate_option specifies a database characteristic. Database characteristics are stored in the data dictionary.

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, theCREATE DATABASE statement creates only a directory under the MySQL data directory. Rules for permissible database names are given inSection 11.2, “Schema Object Names”. If a database name contains special characters, the name for the database directory contains encoded versions of those characters as described inSection 11.2.4, “Mapping of Identifiers to File Names”.

Creating a database directory by manually creating a directory under the data directory (for example, withmkdir) is unsupported in MySQL 9.3.

When you create a database, let the server manage the directory and the files in it. Manipulating database directories and files directly can cause inconsistencies and unexpected results.

MySQL has no limit on the number of databases. The underlying file system may have a limit on the number of directories.

You can also use themysqladmin program to create databases. SeeSection 6.5.2, “mysqladmin — A MySQL Server Administration Program”.