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>
Example:
<code class="sql">CREATE DATABASE my_database;</code>
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>
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>
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>
Example:
<code class="sql">CREATE DATABASE my_database TEMPLATE=my_template_database;</code>
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>
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!