文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

15.1.12 CREATE DATABASE 语句15.1.12 CREATE DATABASE Statement

CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
    [create_option] ...

create_option: [DEFAULT] {
    CHARACTER SET [=] charset_name
  | COLLATE [=] collation_name
  | ENCRYPTION [=] {'Y' | 'N'}
}

CREATE DATABASE带有名字的数据库。要使用该语句,你需要数据库的 CREATE 权限。CREATE SCHEMA 是 CREATE DATABASE“。CREATE DATABASE creates a database with the given name. To use this statement, you need the CREATE privilege for the database. CREATE SCHEMA is a synonym for CREATE DATABASE.

如果数据库存在且你未指定 IF NOT EXISTS。An error occurs if the database exists and you did not specify IF NOT EXISTS.

CREATE DATABASE 不允许在具有活跃 LOCK TABLES 语句。CREATE DATABASE is not permitted within a session that has an active LOCK TABLES statement.

每个create_option指定数据库特征。数据库特征存储在数据字典中。Each create_option specifies a database characteristic. Database characteristics are stored in the data dictionary.

MySQL 中的数据库实现为包含与数据库中表对应的文件的目录。由于在数据库初始创建时没有表,因此 CREATE DATABASE 语句仅在 MySQL 数据目录下创建一个目录。允许的数据库名称规则见 第 11.2 节,“模式对象名称”。如果数据库名称包含特殊字符,则数据库目录的名称包含这些字符的编码版本,如 第 11.2.4 节,“标识符映射到文件名” 中所述。A database in MySQL is implemented as a directory containing files that correspond to tables in the database. Because there are no tables in a database when it is initially created, the CREATE DATABASE statement creates only a directory under the MySQL data directory. Rules for permissible database names are given in Section 11.2, “Schema Object Names”. If a database name contains special characters, the name for the database directory contains encoded versions of those characters as described in Section 11.2.4, “Mapping of Identifiers to File Names”.

在数据目录下通过手动创建目录(例如使用 mkdir)来创建数据库目录在 MySQL 8.4 中不受支持。Creating a database directory by manually creating a directory under the data directory (for example, with mkdir) is unsupported in MySQL 8.4.

当你创建数据库时,让服务器管理目录及其中文件。直接操作数据库目录和文件可能会导致不一致和意外结果。When you create a database, let the server manage the directory and the files in it. Manipulating database directories and files directly can cause inconsistencies and unexpected results.

MySQL 对数据库的数量没有限制。底层文件系统可能对目录的数量有限制。MySQL has no limit on the number of databases. The underlying file system may have a limit on the number of directories.

你也可以使用 mysqladmin 程序来创建数据库。参见 第 6.5.2 节,“mysqladmin — 一个 MySQL 服务器管理程序”。You can also use the mysqladmin program to create databases. See Section 6.5.2, “mysqladmin — A MySQL Server Administration Program”.