mysql数据库数据类型_MySQL-数据类型

mysql数据库数据类型

mysql数据库数据类型

MySQL-数据类型 (MySQL - Data Types)

Properly defining the fields in a table is important to the overall optimization of your database. You should use only the type and size of field you really need to use. For example, do not define a field 10 characters wide, if you know you are only going to use 2 characters. These type of fields (or columns) are also referred to as data types, after the type of data you will be storing in those fields.

正确定义表中的字段对于数据库的整体优化很重要。 您应该只使用您真正需要使用的字段的类型和大小。 例如,如果您只打算使用2个字符,则不要定义10个字符宽的字段。 这些类型的字段(或列)的,也被称为数据类型,将在这些字段被存储的数据的类型之后。

MySQL uses many different data types broken into three categories −

MySQL使用分为三类的许多不同数据类型-

  • Numeric

    数字
  • Date and Time

    日期和时间
  • String Types.

    字符串类型。

Let us now discuss them in detail.

现在让我们详细讨论它们。

数值数据类型 (Numeric Data Types)

MySQL uses all the standard ANSI SQL numeric data types, so if you're coming to MySQL from a different database system, these definitions will look familiar to you.

MySQL使用所有标准的ANSI SQL数字数据类型,因此,如果您是从其他数据库系统访问MySQL的,则这些定义对您来说很熟悉。

The following list shows the common numeric data types and their descriptions −

以下列表显示了常见的数字数据类型及其描述-

  • INT − A normal-sized integer that can be signed or unsigned. If signed, the allowable range is from -2147483648 to 2147483647. If unsigned, the allowable range is from 0 to 4294967295. You can specify a width of up to 11 digits.

    INT-可以带符号或无符号的普通大小的整数。 如果已签名,则允许范围是-2147483648至2147483647。如果未签名,则允许范围是0至4294967295。您可以指定最大11位数字的宽度。

  • TINYINT − A very small integer that can be signed or unsigned. If signed, the allowable range is from -128 to 127. If unsigned, the allowable range is from 0 to 255. You can specify a width of up to 4 digits.

    TINYINT-一个非常小的整数,可以有符号或无符号。 如果已签名,则允许范围是-128到127。如果是未签名,则允许范围是0到255。您可以指定最多4位数字的宽度。

  • SMALLINT − A small integer that can be signed or unsigned. If signed, the allowable range is from -32768 to 32767. If unsigned, the allowable range is from 0 to 65535. You can specify a width of up to 5 digits.

    SMALLINT-一个小的整数,可以有符号或无符号。 如果已签名,则允许范围是-32768到32767。如果是未签名,则允许范围是0到65535。您可以指定最多5位数字的宽度。

  • MEDIUMINT − A medium-sized integer that can be signed or unsigned. If signed, the allowable range is from -8388608 to 8388607. If unsigned, the allowable range is from 0 to 16777215. You can specify a width of up to 9 digits.

    MEDIUMINT-可以签名或不签名的中型整数。 如果已签名,则允许的范围是-8388608至8388607。如果未签名,则允许的范围是0至16777215。您可以指定最多9位数字的宽度。

  • BIGINT − A large integer that can be signed or unsigned. If signed, the allowable range is from -9223372036854775808 to 9223372036854775807. If unsigned, the allowable range is from 0 to 18446744073709551615. You can specify a width of up to 20 digits.

    BIGINT-可以有符号或无符号的大整数。 如果签名,则允许范围是-9223372036854775808至9223372036854775807。如果未签名,则允许范围是0到18446744073709551615。您可以指定最大20位数字的宽度。

  • FLOAT(M,D) − A floating-point number that cannot be unsigned. You can define the display length (M) and the number of decimals (D). This is not required and will default to 10,2, where 2 is the number of decimals and 10 is the total number of digits (including decimals). Decimal precision can go to 24 places for a FLOAT.

    FLOAT(M,D) -不能无符号的浮点数。 您可以定义显示长度(M)和小数位数(D)。 这不是必需的,默认为10,2,其中2是小数位数,而10是数字总数(包括小数位数)。 浮点数的小数精度可以达到24位。

  • DOUBLE(M,D) − A double precision floating-point number that cannot be unsigned. You can define the display length (M) and the number of decimals (D). This is not required and will default to 16,4, where 4 is the number of decimals. Decimal precision can go to 53 places for a DOUBLE. REAL is a synonym for DOUBLE.

    DOUBLE(M,D) -不能无符号的双精度浮点数。 您可以定义显示长度(M)和小数位数(D)。 这不是必需的,并且默认为16,4,其中4是小数位数。 小数精度可以达到53位(双精度)。 REAL是DOUBLE的同义词。

  • DECIMAL(M,D) − An unpacked floating-point number that cannot be unsigned. In the unpacked decimals, each decimal corresponds to one byte. Defining the display length (M) and the number of decimals (D) is required. NUMERIC is a synonym for DECIMAL.

    DECIMAL(M,D) -无法解压缩的解压缩浮点数。 在解压缩的十进制中,每个十进制对应一个字节。 需要定义显示长度(M)和小数位数(D)。 NUMERIC是DECIMAL的同义词。

日期和时间类型 (Date and Time Types)

The MySQL date and time datatypes are as follows −

MySQL日期和时间数据类型如下-

  • DATE − A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31. For example, December 30th, 1973 would be stored as 1973-12-30.

    日期 -YYYY-MM-DD格式的日期,介于1000-01-01和9999-12-31之间。 例如,1973年12月30 将存储为1973-12-30。

  • DATETIME − A date and time combination in YYYY-MM-DD HH:MM:SS format, between 1000-01-01 00:00:00 and 9999-12-31 23:59:59. For example, 3:30 in the afternoon on December 30th, 1973 would be stored as 1973-12-30 15:30:00.

    DATETIME-日期和时间组合,格式为YYYY-MM-DD HH:MM:SS,介于1000-01-01 00:00:00和9999-12-31 23:59:59之间。 例如,1973年12月30 下午3:30将存储为1973-12-30 15:30:00。

  • TIMESTAMP − A timestamp between midnight, January 1st, 1970 and sometime in 2037. This looks like the previous DATETIME format, only without the hyphens between numbers; 3:30 in the afternoon on December 30th, 1973 would be stored as 19731230153000 ( YYYYMMDDHHMMSS ).

    时间戳 -1970年1月1 午夜到2037年之间的时间戳。这看起来像以前的DATETIME格式,只是数字之间没有连字符。 1973年12月30 下午3:30将存储为19731230153000(YYYYMMDDHHMMSS)。

  • TIME − Stores the time in a HH:MM:SS format.

    TIME-以HH:MM:SS格式存储时间。

  • YEAR(M) − Stores a year in a 2-digit or a 4-digit format. If the length is specified as 2 (for example YEAR(2)), YEAR can be between 1970 to 2069 (70 to 69). If the length is specified as 4, then YEAR can be 1901 to 2155. The default length is 4.

    YEAR(M) -以2位数或4位数格式存储年份。 如果将长度指定为2(例如YEAR(2)),则YEAR可以介于1970到2069(70到69)之间。 如果将长度指定为4,则YEAR可以是1901至2155。默认长度是4。

字符串类型 (String Types)

Although the numeric and date types are fun, most data you'll store will be in a string format. This list describes the common string datatypes in MySQL.

尽管数字和日期类型很有趣,但是您将存储的大多数数据都是字符串格式。 此列表描述了MySQL中的常见字符串数据类型。

  • CHAR(M) − A fixed-length string between 1 and 255 characters in length (for example CHAR(5)), right-padded with spaces to the specified length when stored. Defining a length is not required, but the default is 1.

    CHAR(M) -长度介于1到255个字符之间的固定长度字符串(例如CHAR(5)),在存储时用空格填充到指定的长度。 不需要定义长度,但默认值为1。

  • VARCHAR(M) − A variable-length string between 1 and 255 characters in length. For example, VARCHAR(25). You must define a length when creating a VARCHAR field.

    VARCHAR(M) -长度在1到255个字符之间的可变长度字符串。 例如,VARCHAR(25)。 创建VARCHAR字段时必须定义长度。

  • BLOB or TEXT − A field with a maximum length of 65535 characters. BLOBs are "Binary Large Objects" and are used to store large amounts of binary data, such as images or other types of files. Fields defined as TEXT also hold large amounts of data. The difference between the two is that the sorts and comparisons on the stored data are case sensitive on BLOBs and are not case sensitive in TEXT fields. You do not specify a length with BLOB or TEXT.

    BLOB或TEXT-字段的最大长度为65535个字符。 BLOB是“二进制大对象”,用于存储大量二进制数据,例如图像或其他类型的文件。 定义为TEXT的字段也包含大量数据。 两者之间的区别在于,所存储的数据的种类和比较是区分上的BLOB 敏感不区分在文本字段中敏感 。 您没有使用BLOB或TEXT指定长度。

  • TINYBLOB or TINYTEXT − A BLOB or TEXT column with a maximum length of 255 characters. You do not specify a length with TINYBLOB or TINYTEXT.

    TINYBLOB或TINYTEXT -BLOB或TEXT列,最大长度为255个字符。 您未使用TINYBLOB或TINYTEXT指定长度。

  • MEDIUMBLOB or MEDIUMTEXT − A BLOB or TEXT column with a maximum length of 16777215 characters. You do not specify a length with MEDIUMBLOB or MEDIUMTEXT.

    MEDIUMBLOB或MEDIUMTEXT -BLOB或TEXT列,最大长度为16777215个字符。 您没有使用MEDIUMBLOB或MEDIUMTEXT指定长度。

  • LONGBLOB or LONGTEXT − A BLOB or TEXT column with a maximum length of 4294967295 characters. You do not specify a length with LONGBLOB or LONGTEXT.

    LONGBLOB或LONGTEXT -BLOB或TEXT列,最大长度为4294967295个字符。 您没有使用LONGBLOB或LONGTEXT指定长度。

  • ENUM − An enumeration, which is a fancy term for list. When defining an ENUM, you are creating a list of items from which the value must be selected (or it can be NULL). For example, if you wanted your field to contain "A" or "B" or "C", you would define your ENUM as ENUM ('A', 'B', 'C') and only those values (or NULL) could ever populate that field.

    枚举 -一个枚举,这是一个花哨的术语列表。 定义ENUM时,您将创建一个项目列表,必须从中选择值(或者可以为NULL)。 例如,如果希望字段包含“ A”,“ B”或“ C”,则可以将ENUM定义为ENUM(“ A”,“ B”,“ C”),并且仅将这些值(或NULL)定义为ENUM可能会填充该字段。

In the next chapter, we will discuss how to create tables in MySQL.

在下一章中,我们将讨论如何在MySQL中创建表。

翻译自: https://www.tutorialspoint.com/mysql/mysql-data-types.htm

mysql数据库数据类型

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值