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数据库数据类型

mysql数据库数据类型_MySQL-数据类型相关推荐

  1. mysql数据库,当数据类型是float时,查询居然查询不出数据来

    mysql数据库,当数据类型是float时,查询居然查询不出数据来,类似如下: 以后mysql数据库不用float类型,而double类型可以查得出来. 转载于:https://www.cnblogs ...

  2. mysql数据库电话号码类型,mySQL数据库一:数据类型

    Mysql数据库的数据类型.索引.锁.事务和视图 Mysql数据库的数据类型.索引.锁.事务和视图 数据的类型 1)数据类型: 数据长什么样? 数据需要多少空间来存放? 系统内置数据类型和用户定义数据 ...

  3. MySQL数据库基础:数据类型详解-文本字符串类型

    前言 正好趁着这次一起学习复习一下MySQL数据库的基本知识.也是一直在用这个数据库,有些基础的知识点长久不用就会遗忘,就比如数据类型溢出的问题,很多时候建表的时候随便给定个类似,结果导入数据的时候报 ...

  4. mysql布尔数据类型_MySQL数据类型

    在本教程中,您将了解MySQL数据类型以及如何在MySQL中设计数据库时有效地使用它们. 数据库表包含具有特定数据类型(如数字或字符串)的多个列. MySQL提供更多的数据类型,而不仅仅是数字或字符串 ...

  5. mysql 51cto 数据类型_MYSQL 数据类型 详解

    请问在数据类型里 1,char,nchar,nvarchar,varchar有什么区别? 2,text和ntext有什么区别以及和上面各种字符类有什么区别? 3,关于带big和带small的类型,比如 ...

  6. mysql数据库语法_MySQL数据库基本语法

    SQL WHAT(SQL是什么?) Structured Query Language:结构化查询语⾔ WHY(为何要使用SQL?) 难道仅仅使用SQL Server Management Studi ...

  7. mysql数据库属性_mysql - 数据库操作和数据属性

    数据库操作 启动 mysql, mac 可通过 brew 安装 mysql 后启动. window 需要手动配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14mysql.serve ...

  8. mysql数据库应用_MySQL数据库应用 从入门到精通 学习笔记

    以下内容是学习<MySQL数据库应用 从入门到精通>过程中总结的一些内容提要,供以后自己复现使用. 一:数据库 查看所有数据库:SHOW DATABASES 创建数据库:CREATE DA ...

  9. mysql数据库语法_MySQL数据库语法(一)

    MySQL数据库语法 数据库管理系统(DBMS)的概述 什么是DBMS:数据的仓库 方便查询 可存储的数据量大 保证数据的完整.一致 安全可靠 DBMS的发展:今天主流数据库为关系型数据库管理系统(R ...

  10. mysql_ init数据类型_mysql数据类型

    mysql三-2:数据类型 一 介绍 二 数值类型 三 日期类型 四 字符串类型 五 枚举类型与集合类型 一 介绍 存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己的宽度 ...

最新文章

  1. 台式电脑没鼠标怎么移动光标_台式机没有鼠标 怎么控制光标
  2. [js高手之路] html5 canvas系列教程 - 线条样式(lineWidth,lineCap,lineJoin,setLineDash)
  3. ARM中各始终之间的关系,FCLK HCLK PCLK的关系
  4. leetcode - 646. 最长数对链
  5. java html写入到word文档_java 使用jacob将html页面写入word
  6. 第二周Python笔记 数据类型 字典
  7. 【English】十六、时间相关
  8. php考试试卷,php测试题(一)
  9. ipython 安装_IPYTHON安装.DOC
  10. python导出excel 身份证_如何使用Python导出Excel文件?
  11. 伪加密文件的破解方法
  12. Matplotlib 应用
  13. Oracle 后台进程详解
  14. linux 如何加定时任务,linux系统添加定时任务
  15. Hello, World——从零到实盘0
  16. NPDP产品经理小知识-质量功能展开和质量屋
  17. BLE协议栈学习2——OSAL
  18. 牛鞭效应matlab代码,牛鞭效应在啤酒游戏中的运用.doc
  19. IDEA支持VUE的做法
  20. vue前端项目启动出错处理

热门文章

  1. 什么是计算机网络(世俗理解)
  2. 什么是云原生数据库?
  3. 想知道香港汇丰银行如何开户吗?
  4. Android GMS认证项总结
  5. LNK2019解决思路
  6. grbl源码解析——速度前瞻(2)
  7. java 编程联系_《JAVA程序设计》结对编程联系_四则运算(第一周:阶段总结)...
  8. HDMI光纤线,英文称呼:hdmi AOC Cable,又被称为有源光缆。
  9. 阿里云服务器绑定域名、esc绑定域名、域名备案
  10. 大数据技术背景介绍(开号篇)