Create and modify MySQL database syntax, mysql database syntax
1. Create Database Syntax:
CREATE {DATABASE | SCHEMA} [if not exists] db_name
[Create_specification [, create_specification]...]
Note:CREATE DATABASECreate and name a database. If you want to use create database, you needObtain database CREATE permission. IF a database EXISTS and you do NOT specify if not exists, an error occurs.
Create_specification:
[DEFAULT] character set charset_name
| [DEFAULT] COLLATE collation_name
Note:Create_specificationSpecifies the features of a database. The database features are stored in the db. opt file in the database directory.CHARACTER SETClause is used to specify the default database character set.COLLATEClause is used to specify the default full-order database.
Some directories contain files that correspond to tables in the database. The execution methods of databases in MySQL are the same as those of these directories. Because there is no table in the DATABASE when the DATABASE is just created, create database creates only one directory. This directory is located under the MySQL data directory And the db. opt file.
If you manually create a directory under the Data Directory (for example, mkdir), the server will regard it as a database directory and display it in the output of show databases.
You can also use create schema.
----------
2. Modify the database Syntax:
ALTER {DATABASE | SCHEMA} [db_name] alter_specification [, alter_specification]...
Note:ALTER DATABASEUsed to change the global features of a database. These features are stored in the db. opt file in the database directory. To use alter database, you needObtain database ALTER permission.
Alter_specification:
[DEFAULT] character set charset_name
| [DEFAULT] COLLATE collation_name
Note:CHARACTER SETThe sub-statement is used to change the default database character set;COLLATEThe sub-statement is used to change the entire sequence of the default database.
The database name [db_name] can be ignored. In this case, the statement corresponds to the default database. You can also use alter schema.