Home > Database > Mysql Tutorial > CREATE DATABASE statement explained

CREATE DATABASE statement explained

一个新手
Release: 2017-09-30 10:08:01
Original
3473 people have browsed it

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
Copy after login

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 ...;
Copy after login

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 |
+-------+------+----------------------------------------------+
Copy after login

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';
Copy after login

The above is the detailed content of CREATE DATABASE statement explained. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template