All pages
Powered by GitBook
1 of 1

Loading...

CREATE DATABASE

Create a new database container. This command initializes a new database namespace with optional character set and collation settings.

Syntax

Description

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

For valid identifiers to use as database names, see .

OR REPLACE

If the optional OR REPLACE clause is used, it acts as a shortcut for:

IF NOT EXISTS

When the IF NOT EXISTS clause is used, MariaDB will return a warning instead of an error if the specified database already exists.

COMMENT

The maximum length of a comment is 1024 bytes. If the comment length exceeds this length, an error/warning code 4144 is thrown. The database comment is also added to the db.opt file, as well as to the .

Comments added for databases do not exist.

Examples

Setting the . See for more details.

See Also

This page is licensed: GPLv2, originally from

CREATE [OR REPLACE] {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
    [create_specification] ...

create_specification:
    [DEFAULT] CHARACTER SET [=] charset_name
  | [DEFAULT] COLLATE [=] collation_name
  | COMMENT [=] 'comment'
SHOW DATABASES
  • Character Sets and Collations

  • Information Schema SCHEMATA Table

  • CREATE privilege
    Identifier Names
    information_schema.schemata table
    character sets and collation
    Setting Character Sets and Collations
    Identifier Names
    DROP DATABASE
    SHOW CREATE DATABASE
    ALTER DATABASE
    fill_help_tables.sql
    DROP DATABASE IF EXISTS db_name;
    CREATE DATABASE db_name ...;
    CREATE DATABASE db1;
    Query OK, 1 row affected (0.18 sec)
    
    CREATE DATABASE db1;
    ERROR 1007 (HY000): Can't create database 'db1'; database exists
    
    CREATE OR REPLACE DATABASE db1;
    Query OK, 2 rows affected (0.00 sec)
    
    CREATE DATABASE IF NOT EXISTS db1;
    Query OK, 1 row affected, 1 warning (0.01 sec)
    
    SHOW WARNINGS;
    +-------+------+----------------------------------------------+
    | Level | Code | Message                                      |
    +-------+------+----------------------------------------------+
    | Note  | 1007 | Can't create database 'db1'; database exists |
    +-------+------+----------------------------------------------+
    CREATE DATABASE czech_slovak_names 
      CHARACTER SET = 'keybcs2'
      COLLATE = 'keybcs2_bin';
    CREATE DATABASE presentations COMMENT 'Presentations for conferences';