Create a MySQL database (CREATE DATABASE statement)

It can be seen as a specialized database of data objects stored in a container, where the data object includes tables, views, triggers, stored procedures, etc., where the table is the most basic data object. Before you create a data object in the MySQL database, first create a good database.

 

In MySQL, you can use the  CREATE DATABASE  to create a database statement syntax is as follows:

CREATE DATABASE [IF NOT EXISTS] <database name>
[[the DEFAULT] the CHARACTER the SET <character set name>] [[DEFAULT] COLLATE <collation name>];

[ ]The content is optional. Syntax is as follows:

  • <Database name>: Create a database name. MySQL's catalog will indicate how the data storage area MySQL database, the database name must conform to the operating system folder naming conventions, pay attention to case-insensitive in MySQL.
  • IF NOT EXISTS: judge before creating a database to perform the operation only if the database does not yet exist. This option can be used to avoid repeating mistakes and create the database already exists.
  • [DEFAULT] CHARACTER SET: Specifies the default character set of the database.
  • [DEFAULT] COLLATE: default collation specified character set.

Two different concepts MySQL character set (CHARACTER) and collation (COLLATION): character set is used to define MySQL storage string, string comparisons collation defines the way to solve the problem of sorting and grouping of characters.

Character set and collation are many relationship, each corresponding to at least one character set collation, MySQL supports nearly 200 kinds of collation 39 kinds of character sets.

Example 1: The simplest MySQL database creation statements

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

mysql> CREATE DATA

Guess you like

Origin blog.csdn.net/mysqlsd/article/details/103652912