Home  >  Article  >  Database  >  CREATE DATABASE statement explained

CREATE DATABASE statement explained

一个新手
一个新手Original
2017-09-30 10:08:013411browse

This article is the translation of mariadb official manual: CREATE DATABASE.

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 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.

OR REPLACE

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 ...;

IF NOT EXISTS

When the IF NOT EXISTS clause is used, when the specified database already exists , MariaDB will return 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 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn