SQL reference (MySQL and MariaDB dialects)

CREATE DATABASE, DROP DATABASE and SHOW CREATE DATABASE

How to create, remove and describe a database through the MySQL and MariaDB front-ends, and what the character set options do (nothing).

CREATE DATABASE makes a new database. DROP DATABASE removes a database with all its tables, views, routines and triggers. In Raft DB a SQL database is a Raft DB database; the two words DATABASE and SCHEMA mean the same.

Syntax#

SQL
CREATE { DATABASE | SCHEMA } [IF NOT EXISTS] db_name
    [create_option] ...

create_option:
    [DEFAULT] CHARACTER SET [=] charset_name
  | [DEFAULT] CHARSET [=] charset_name
  | [DEFAULT] COLLATE [=] collation_name

DROP { DATABASE | SCHEMA } [IF EXISTS] db_name

SHOW CREATE { DATABASE | SCHEMA } [IF NOT EXISTS] db_name

Arguments#

NameMeaningDefault
db_nameName of the database. Any name MySQL allows is accepted (spaces, accents, $, up to 64 characters, not ending in a space). The characters ., /, \ and control characters are refused. Names that start with __rdb_, __tmp or __u_ belong to the front-end and are refused.none
IF NOT EXISTSCREATE: do nothing, with a warning, when the database exists.off
IF EXISTSDROP: do nothing, with a warning, when the database does not exist.off
create_optionEverything after the name is read up to the end of the statement and ignored.none

Remarks#

  • The parser takes everything after the name as options and skips it. It does not check the option words. Every text in Raft DB is stored as utf8mb4; the character set and collation you write do not change it. SHOW CREATE DATABASE prints the utf8mb4 default of the dialect.
  • Privileges: CREATE on the database name for CREATE DATABASE, DROP on the database for DROP DATABASE. A bootstrap administrator of the front-end's configuration file has every privilege.
  • SHOW DATABASES lists information_schema and the databases the account may see. Each front-end shows only its own databases (D60). MariaDB lists them in one alphabetical order.
  • DROP DATABASE removes every table of the database. It cannot be rolled back.
  • The system schemas mysql, performance_schema and sys are not real databases here.

Not supported yet#

  • ALTER DATABASE (answered with error 1235).
  • Character set and collation per database: the options are read, not applied.

Examples#

SQL
CREATE DATABASE shop;
CREATE DATABASE IF NOT EXISTS shop DEFAULT CHARACTER SET utf8mb4;
USE shop;
SHOW CREATE DATABASE shop;
DROP DATABASE IF EXISTS shop;

See also#