Home > Database > Mysql Tutorial > body text

What are the statements for creating a database in mysql?

下次还敢
Release: 2024-04-05 18:48:24
Original
825 people have browsed it

MySQL statement to create a database

1. Use the CREATE DATABASE statement

The easiest way is to useCREATE DATABASE statement, the syntax is as follows:

<code class="sql">CREATE DATABASE database_name;</code>
Copy after login

Example:

<code class="sql">CREATE DATABASE my_database;</code>
Copy after login

2. Specify the storage engine and character set

Yes Specify the storage engine and character set of the database. The syntax is as follows:

<code class="sql">CREATE DATABASE database_name
ENGINE=storage_engine CHARSET=charset;</code>
Copy after login

Among them:

  • storage_engine can be InnoDB, MyISAM or other supported storage engine.
  • charset can be utf8, latin1, or other supported character set.

Example:

<code class="sql">CREATE DATABASE my_database ENGINE=InnoDB CHARSET=utf8;</code>
Copy after login

3. Specify a template database

You can create a new database by specifying a template database , the syntax is as follows:

<code class="sql">CREATE DATABASE database_name TEMPLATE=template_database;</code>
Copy after login

Example:

<code class="sql">CREATE DATABASE my_database TEMPLATE=my_template_database;</code>
Copy after login

4. Options

CREATE DATABASE statement You can also include the following options:

  • DEFAULT CHARACTER SET: Specifies the default character set for the database.
  • DEFAULT COLLATE: Specifies the default collation of the database.
  • MAX_QUERIES_PER_HOUR: Limits the number of queries allowed to be executed on the database per hour.
  • MAX_UPDATES_PER_HOUR: Limits the number of updates allowed to be performed on the database per hour.

Example:

<code class="sql">CREATE DATABASE my_database DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;</code>
Copy after login

The above is the detailed content of What are the statements for creating a database in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!