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#
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_nameArguments#
| Name | Meaning | Default |
|---|---|---|
db_name | Name 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 EXISTS | CREATE: do nothing, with a warning, when the database exists. | off |
IF EXISTS | DROP: do nothing, with a warning, when the database does not exist. | off |
create_option | Everything 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 DATABASEprints theutf8mb4default of the dialect. - Privileges:
CREATEon the database name forCREATE DATABASE,DROPon the database forDROP DATABASE. A bootstrap administrator of the front-end's configuration file has every privilege. SHOW DATABASESlistsinformation_schemaand the databases the account may see. Each front-end shows only its own databases (D60). MariaDB lists them in one alphabetical order.DROP DATABASEremoves every table of the database. It cannot be rolled back.- The system schemas
mysql,performance_schemaandsysare 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#
CREATE DATABASE shop;
CREATE DATABASE IF NOT EXISTS shop DEFAULT CHARACTER SET utf8mb4;
USE shop;
SHOW CREATE DATABASE shop;
DROP DATABASE IF EXISTS shop;