Home  >  Article  >  Database  >  What is the statement to create a database?

What is the statement to create a database?

王林
王林Original
2021-01-28 15:38:4327656browse

The statement to create a database is: [CREATE DATABASE [IF NOT EXISTS] e5c249aa15ff4c64720f99bfaecf8a60 [[DEFAULT] CHARACTER SET 0aa526f88c58c33e45ef8249d2e6cba7] [[DEFAULT] COLLATE a44714ebb7e6be09b074e7d7cb760a09];].

What is the statement to create a database?

The operating environment of this article: windows10 system, mysql 5.7, thinkpad t480 computer.

(Learning video sharing: mysql video tutorial)

Detailed introduction:

In MySQL, you can use the CREATE DATABASE statement to create a database, syntax format As follows: The content in

CREATE DATABASE [IF NOT EXISTS] <数据库名>
[[DEFAULT] CHARACTER SET <字符集名>] 
[[DEFAULT] COLLATE <校对规则名>];

[ ] is optional. The syntax is as follows:

75a531a7de735e17c67a53ba0f5274e3: The name of the created database. The data storage area of ​​MySQL will represent the MySQL database in a directory format, so the database name must comply with the folder naming rules of the operating system, cannot start with a number, and should be as meaningful as possible. Note that MySQL is not case sensitive.

IF NOT EXISTS: Make a judgment before creating the database. The operation can only be performed if the database does not currently exist. This option can be used to avoid duplicate creation errors when the database already exists.

[DEFAULT] CHARACTER SET: Specifies the character set of the database. The purpose of specifying the character set is to avoid garbled data stored in the database. If you do not specify a character set when creating the database, the system's default character set is used.

[DEFAULT] COLLATE: Specifies the default collation rule for the character set.

Example:

Create a database named test_db in MySQL. Enter the SQL statement CREATE DATABASE test_db; in the MySQL command line client to create a database. The entered SQL statement and execution results are as follows.

mysql> CREATE DATABASE test_db;
Query OK, 1 row affected (0.12 sec);

In the "Query OK, 1 row affected (0.12 sec);" prompt, "Query OK" means that the above command was executed successfully, and "1 row affected" means that the operation only affected one row in the database. The record, "0.12 sec" records the time of operation execution.

Related recommendations: mysql tutorial

The above is the detailed content of What is the statement to create a database?. 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