下表描述了每种标识符类型的最大长度。The following table describes the maximum length for each type of identifier.
| 标识符类型Identifier Type | 最大长度(字符)Maximum Length (characters) |
|---|---|
| 数据库Database | 64 |
| 表Table | 64 |
| 列Column | 64 |
| 索引Index | 64 |
| 约束Constraint | 64 |
| 存储程序Stored Program | 64 |
| 视图View | 64 |
| 表空间Tablespace | 64 |
| 服务器Server | 64 |
| 日志文件组Log File Group | 64 |
| 别名Alias | 256(见表后异常)256 (see exception following table) |
| 复合语句标签Compound Statement Label | 16 |
| 用户定义变量User-Defined Variable | 64 |
| 资源组Resource Group | 64 |
在 CREATE
VIEW 语句中,列名的别名会检查最大列长度是否为 64 个字符(而不是最大别名长度 256 个字符)。Aliases for column names in CREATE
VIEW statements are checked against the maximum column
length of 64 characters (not the maximum alias length of 256
characters).
对于不包含约束名称的约束定义,服务器会内部生成一个名称,该名称来源于相关的表名。例如,内部生成的外键和 CHECK 约束名称由表名加上 _ibfk_ 或 _chk_ 及一个数字组成。如果表名接近约束名称的长度限制,为约束名称所需的额外字符可能会导致该名称超过限制,从而导致错误。For constraint definitions that include no constraint name, the
server internally generates a name derived from the associated
table name. For example, internally generated foreign key and
CHECK constraint names consist of the table
name plus _ibfk_ or _chk_
and a number. If the table name is close to the length limit for
constraint names, the additional characters required for the
constraint name may cause that name to exceed the limit,
resulting in an error.
标识符使用 Unicode (UTF-8) 存储。这适用于表定义中的标识符以及存储在 mysql 数据库的授权表中的标识符。授权表中标识符字符串列的大小以字符为单位。您可以使用多字节字符,而无需减少这些列中允许存储值的字符数。Identifiers are stored using Unicode (UTF-8). This applies to
identifiers in table definitions and to identifiers stored in
the grant tables in the mysql database. The
sizes of the identifier string columns in the grant tables are
measured in characters. You can use multibyte characters without
reducing the number of characters permitted for values stored in
these columns.
MySQL 帐户名中的值,例如用户名和主机名,是字符串,而不是标识符。有关这些值在授权表中存储的最大长度的信息,请参见 授权表范围列属性。Values such as user name and host names in MySQL account names are strings rather than identifiers. For information about the maximum length of such values as stored in grant tables, see Grant Table Scope Column Properties.