Translation: create database statement, createdatabase
This article is the translation of the mariadb official manual: create database.
Original article: https://mariadb.com/kb/en/create-database/
Https://mariadb.com/kb/zh-cn/create-database/ I submitted to the MariaDB official manual
Syntax
CREATE [OR REPLACE] {DATABASE | SCHEMA} [IF NOT EXISTS] db_name [create_specification] ...create_specification: [DEFAULT] CHARACTER SET [=] charset_name | [DEFAULT] COLLATE [=] collation_name
Description
Create database creates a DATABASE with a given name. This statement requires the CREATE permission on the database. Create schema is a synonym for create database. IF the if not exists clause is used, a warning message is returned instead of an error when the database already EXISTS.
OR REPLACE
MariaDB starting with 10.1.3 introduces the or replace clause in MariaDB 10.1.3. If an optional or replace clause is used, it is short for the following statement:
DROP DATABASE IF EXISTS db_name;CREATE DATABASE db_name ...;
IF NOT EXISTS
When the if not exists clause is used, when the specified database already EXISTS, MariaDB returns a warning instead of an error message.
Example
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 character sets and sorting rules. For more information, see set character sets and sorting rules.
CREATE DATABASE czech_slovak_names CHARACTER SET = 'keybcs2' COLLATE = 'keybcs2_bin';
Go back to the Linux series article outline: workshop!