Home >Database >Mysql Tutorial >CREATE DATABASE statement explained
This article is the translation of mariadb official manual: CREATE DATABASE.
CREATE [OR REPLACE] {DATABASE | SCHEMA} [IF NOT EXISTS] db_name [create_specification] ... create_specification: [DEFAULT] CHARACTER SET [=] charset_name | [DEFAULT] COLLATE [=] collation_name
CREATE DATABASE Creates a database with the given name. This statement requires CREATE permission on the database. CREATE SCHEMA is a synonym for CREATE DATABASE. If the IF NOT EXISTS clause is used, a warning message will be returned instead of an error when the database already exists.
MariaDB starting with 10.1.3 The OR REPLACE clause was introduced in MariaDB 10.1.3. If the optional OR REPLACE clause is used, it is the abbreviation of the following statement:
DROP DATABASE IF EXISTS db_name;CREATE DATABASE db_name ...;
When the IF NOT EXISTS clause is used, when the specified database already exists , MariaDB will return a warning instead of an error message.
CREATE DATABASE db1;Query OK, 1 row affected (0.18 sec)CREATE DATABASE db1;ERROR 1007 (HY000): Can't create database 'db1'; database existsCREATE 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 | +-------+------+----------------------------------------------+
Set the character set and collation. See Setting Character Set and Collation Rules for details.
CREATE DATABASE czech_slovak_names CHARACTER SET = 'keybcs2' COLLATE = 'keybcs2_bin';
The above is the detailed content of CREATE DATABASE statement explained. For more information, please follow other related articles on the PHP Chinese website!