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:
CREATE DATABASE database_name;
Example:
CREATE DATABASE my_database;
2. Specify the storage engine and character set
Yes Specify the storage engine and character set of the database. The syntax is as follows:
CREATE DATABASE database_name ENGINE=storage_engine CHARSET=charset;
Among them:
storage_engine
can be InnoDB
, MyISAM
or other supported storage engine. charset
can be utf8
, latin1
, or other supported character set. Example:
CREATE DATABASE my_database ENGINE=InnoDB CHARSET=utf8;
3. Specify a template database
You can create a new database by specifying a template database , the syntax is as follows:
CREATE DATABASE database_name TEMPLATE=template_database;
Example:
CREATE DATABASE my_database TEMPLATE=my_template_database;
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:
CREATE DATABASE my_database DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
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!