Create and modify MySQL database syntax, mysql database syntax

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.