一般情况下,我们不太会纠结用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