一般情况下,我们不太会纠结用Varchar或text数据类型。
比如说,我们要存储邮箱,我们自然会用varchar,不会想到用text。而当我们要存储一段话的时候,选了text,感觉varchar也够用。当然感觉是没有用的,我们可以研究一下。

TEXT and BLOB is stored off the table with the table just having a pointer to the location of the actual storage.

VARCHAR is stored inline with the table. VARCHAR is faster when the size is reasonable, the tradeoff of which would be faster depends upon your data and your hardware, you'd want to benchmark a realworld scenario with your data.

以上引用大致是说:TEXT 和 BLOB 相当于是存储了一个位置指针,这个指针指向一个表结构数据。而VARCHAR是表内级别的数据单元。通过指针去找到表再找到数据,相对而言比表内找到一个数据要效率低些。当然TEXT、BLOB存储量比VARCHAR是要大些。

以下有个清单有助于选定数据该用哪种类型:

VARCHAR(X)

Case: user name, email, country, subject, password

TEXT

Case: messages, emails, comments, formatted text, html, code, images, links

MEDIUMTEXT

Case: large json bodies, short to medium length books, csv strings

LONGTEXT

Case: textbooks, programs, years of logs files, harry potter and the goblet of fire, scientific research logging

参考资料

http://stackoverflow.com/questions/2023481/mysql-large-varchar-vs-text

Mysql VARCHAR(X) vs TEXT的更多相关文章

  1. MySQL varchar 最大长度,text 类型占用空间剖析

    MySQL 表中行的最大大小为 65,534(实际行存储从第二个字节开始)字节.每个 BLOB 和 TEXT 列只占其中的 5 至 9 个字节. 那么来验证下 varchar 类型的实际最大长度: 测 ...

  2. pandas对象保存到mysql出错提示“BLOB/TEXT column used in key specification without a key length”解决办法

    问题 将DataFrame数据保存到mysql中时,出现错误提示: BLOB/TEXT column used in key specification without a key length 原因 ...

  3. Mysql varchar长度问题

    http://dinglin.iteye.com/blog/914276 http://www.cnblogs.com/fakis/archive/2011/03/07/1976532.html   ...

  4. MySQL VARCHAR字段最大长度到底是多少

    MySQL VARCHAR字段最大长度到底是多少   varchar(n),n表示什么? MySQL5.0.3之前varchar(n)这里的n表示字节数 MySQL5.0.3之后varchar(n)这 ...

  5. MySQL中tinytext、text、mediumtext和longtext等各个类型详解

    转: MySQL中tinytext.text.mediumtext和longtext等各个类型详解 2018年06月13日 08:55:24 youcijibi 阅读数 26900更多 个人分类: 每 ...

  6. 操作MySQL出错提示“BLOB/TEXT column request_data in key specification without a key length”解决办法

    错误原因: 查阅资料后才知道,原来Mysql数据库对于BLOB/TEXT这样类型的数据结构只能索引前N个字符.所以这样的数据类型不能作为主键,也不能是UNIQUE的.所以要换成VARCHAR,但是VA ...

  7. [MySQL-1] mysql error 1101 blob/text column can't have a default value

    在MySQL Query Browser上创建一个含有TEXT类型的字段,创建不成功,报错:mysql error 1101 blob/text column can't have a default ...

  8. mysql varchar vs oracle varchar2

    1.错误提示: mysql的Data truncation: Data too long for column 'path' at row 1 错误原因: 1.字段过长而导致出错的, 2. 可能是因为 ...

  9. mysql varchar integer

    MySQL 中将 varchar 字段转换成数字进行排序 - MySQL - 大象笔记 https://www.sunzhongwei.com/order-by-varchar-field-which ...

随机推荐

  1. 【面试题】TB

    动态库与静态库区别: 堆栈区别,这样区分的意义: 不用第三个变量,交换两个变量的值: 链表公共节点: 判断链表是否有环: 常用排序算法,哪个可以链表实现: 哪科学的好,感兴趣: 项目介绍,遇到的最大问 ...

  2. jQuery回车键提交表单

    $(document).keyup(function(event) {     if(event.keyCode==13)     {         $('btnSubmit').trigger(& ...

  3. Android service介绍和启动方式

    1.Android service的作用: service通常是用来处理一些耗时操作,或后台执行不提供用户交互界面的操作,例如:下载.播放音乐. 2.Android service的生命周期: ser ...

  4. DrawingContext.Pop Method

    The following example shows the effect of the Pop command. using System; using System.Windows; using ...

  5. java unicode转中文

    public static String unicodeToString(String str) { Pattern pattern = Pattern.compile("(\\\\u(\\ ...

  6. SIFT特征提取分析

    SIFT特征提取分析 sift 关键点,关键点检测 读'D. G. Lowe. Distinctive Image Features from Scale-Invariant Keypoints[J] ...

  7. Ubuntu下SVN配置

    今天上午写了一个脚本,然后想起来现在写的R脚本,常常在分析过程中就直接改掉了.隐隐还是觉得存在隐患,想着svn部署应该不会太难,于是就直接动手干了. 弄了一上午的时间,感觉还是花了点时间. 这里有篇b ...

  8. [转]shell 变量替换

    转自:http://blog.csdn.net/xuhongning/article/details/6191515 1,参数替换: 不含有“:”的,只要定义了,就生效,不管是否为空 含有“:”的,即 ...

  9. Webpack打包进阶

    说在前面 由于使用了React直出,页面各项性能指标使人悦目.本篇将深入探讨目前PC部落所采用webpack打包优化策略,以及探讨PC部落并未使用的 webpack Code Splitting 代码 ...

  10. Leetcode Remove Nth Node From End of List

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...