MySQL Create and modify database syntax

Source: Internet
Author: User
Tags mysql create

1. Create DATABASE syntax:

CREATE {DATABASE | SCHEMA} [IF not EXISTS] Db_name
[Create_specification [, Create_specification] ...]

Note: CREATE DATABASE is used for creating databases and naming them. If you want to use CREATE database, you need to get the Create permissions for the databases . If the database exists and you do not specify an if not EXISTS, an error occurs.

Create_specification:
[DEFAULT] CHARACTER SET Charset_name
| [DEFAULT] COLLATE collation_name

Note: Thecreate_specification option is used to specify the attributes of the database. Database attributes are stored in the db.opt file in the database directory. The CHARACTER set clause is used to specify the default database character set. The COLLATE clause is used to specify the default database collation.

Some directories contain files that correspond to tables in the database. Databases in MySQL are executed in the same way as these directories do. Because there are no tables in the database when the database was 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, using mkdir), the server considers this a database directory and displays it in the output of show databases.

You can also use the Create SCHEMA.

----------

2. Modify the database syntax:

ALTER {DATABASE | SCHEMA} [Db_name] alter_specification [, alter_specification] ...

NOTE:alter database is used to change the global nature of the databases. These attributes are stored in the db.opt file in the database directory. In order to use ALTER DATABASE, you need to obtain the ALTER permission for the databases .

alter_specification:
[DEFAULT] CHARACTER SET charset_name

| [DEFAULT] COLLATE collation_name

Note: TheCHARACTER set clause is used to change the default database character set; theCOLLATE clause is used to change the default database collation.

The database name [db_name] can be ignored, at which point the statement corresponds to the default database. You can also use the Alter SCHEMA.

MySQL Create and modify database syntax

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.