- 13.1 数值数据类型13.1 Numeric Data Types
- 13.1.1 数值数据类型语法13.1.1 Numeric Data Type Syntax
- 13.1.2 整数类型(精确值) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT
- 13.1.3 定点类型(精确值) - DECIMAL, NUMERIC13.1.3 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC
- 13.1.4 浮点类型(近似值) - FLOAT, DOUBLE13.1.4 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE
- 13.1.5 位值类型 - BIT13.1.5 Bit-Value Type - BIT
- 13.1.6 数值类型属性13.1.6 Numeric Type Attributes
- 13.1.7 超出范围和溢出处理13.1.7 Out-of-Range and Overflow Handling
- 13.2 日期和时间数据类型13.2 Date and Time Data Types
- 13.2.1 日期和时间数据类型语法13.2.1 Date and Time Data Type Syntax
- 13.2.2 DATE、DATETIME 和 TIMESTAMP 类型13.2.2 The DATE, DATETIME, and TIMESTAMP Types
- 13.2.3 TIME 类型13.2.3 The TIME Type
- 13.2.4 YEAR 类型13.2.4 The YEAR Type
- 13.2.5 TIMESTAMP 和 DATETIME 的自动初始化和更新13.2.5 Automatic Initialization and Updating for TIMESTAMP and DATETIME
- 13.2.6 时间值中的小数秒13.2.6 Fractional Seconds in Time Values
- 13.2.7 MySQL 使用的历法13.2.7 What Calendar Is Used By MySQL?
- 13.2.8 日期和时间类型之间的转换13.2.8 Conversion Between Date and Time Types
- 13.2.9 日期中的两位数年份13.2.9 2-Digit Years in Dates
- 13.3 字符串数据类型13.3 String Data Types
- 13.4 空间数据类型13.4 Spatial Data Types
- 13.4.1 空间数据类型13.4.1 Spatial Data Types
- 13.4.2 OpenGIS 几何模型13.4.2 The OpenGIS Geometry Model
- 13.4.3 支持的空间数据格式13.4.3 Supported Spatial Data Formats
- 13.4.4 几何的良构性和有效性13.4.4 Geometry Well-Formedness and Validity
- 13.4.5 空间参考系统支持13.4.5 Spatial Reference System Support
- 13.4.6 创建空间列13.4.6 Creating Spatial Columns
- 13.4.7 填充空间列13.4.7 Populating Spatial Columns
- 13.4.8 获取空间数据13.4.8 Fetching Spatial Data
- 13.4.9 优化空间分析13.4.9 Optimizing Spatial Analysis
- 13.4.10 创建空间索引13.4.10 Creating Spatial Indexes
- 13.4.11 使用空间索引13.4.11 Using Spatial Indexes
- 13.5 JSON 数据类型13.5 The JSON Data Type
- 13.6 数据类型默认值13.6 Data Type Default Values
- 13.7 数据类型存储要求13.7 Data Type Storage Requirements
- 13.8 为列选择合适的类型13.8 Choosing the Right Type for a Column
- 13.9 使用其他数据库引擎的数据类型13.9 Using Data Types from Other Database Engines
MySQL 支持几类 SQL 数据类型:数值类型、日期和时间类型、字符串(字符和字节)类型、空间类型,以及 JSON 数据类型。本章提供各类别数据类型概述和更详细的属性说明,以及数据类型存储需求的汇总。初步概述故意简略。有关特定数据类型的更多信息,例如可以指定值的允许格式,请参考更详细的描述。MySQL supports SQL data types in
several categories: numeric types, date and time types, string
(character and byte) types, spatial types, and the
JSON data type. This chapter provides
an overview and more detailed description of the properties of the
types in each category, and a summary of the data type storage
requirements. The initial overviews are intentionally brief. Consult
the more detailed descriptions for additional information about
particular data types, such as the permissible formats in which you
can specify values.
数据类型描述使用以下约定:Data type descriptions use these conventions:
对于整数类型,
M表示最大显示宽度。对于浮点和定点类型,M是可存储的总位数(精度)。对于字符串类型,M是最大长度。M的最大允许值取决于数据类型。For integer types,Mindicates the maximum display width. For floating-point and fixed-point types,Mis the total number of digits that can be stored (the precision). For string types,Mis the maximum length. The maximum permissible value ofMdepends on the data type.D适用于浮点和定点类型,表示小数点后的位数(小数位数)。最大可能值为 30,但不应大于M−2。Dapplies to floating-point and fixed-point types and indicates the number of digits following the decimal point (the scale). The maximum possible value is 30, but should be no greater thanM−2.fsp适用于TIME、DATETIME和TIMESTAMP类型,表示秒的小数精度;也就是秒的小数部分之后的数字个数。若给定,fsp的值必须在 0 到 6 之间。值为 0 表示没有小数部分。如果省略,默认精度为 0。(这与标准 SQL 的默认值 6 不同,这是为了兼容早期 MySQL 版本。)fspapplies to theTIME,DATETIME, andTIMESTAMPtypes and represents fractional seconds precision; that is, the number of digits following the decimal point for fractional parts of seconds. Thefspvalue, if given, must be in the range 0 to 6. A value of 0 signifies that there is no fractional part. If omitted, the default precision is 0. (This differs from the standard SQL default of 6, for compatibility with previous MySQL versions.)方括号(
[和])表示类型定义中可选的部分。Square brackets ([and]) indicate optional parts of type definitions.