Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL TEXT or VARCHAR

We have a very large historical table that contains a column with at most 500 UTF8 characters, and the disk space grows really fast!

We're having at least 2 million rows a day... and we were wondering which would do a better job (mostly in storage but in performance as well)? TEXT or VARCHAR(512)?

like image 677
r1th4l1n Avatar asked Nov 08 '10 22:11

r1th4l1n


People also ask

Which is better VARCHAR or TEXT in MySQL?

In most circumstances, VARCHAR provides better performance, it's more flexible, and can be fully indexed. If you need to store longer strings, use MEDIUMTEXT or LONGTEXT, but be aware that very large amounts of data can be stored in columns of these types.

What is difference between CHAR VARCHAR and TEXT in MySQL?

CHAR items, which are fixed length, are the fastest to store and retrieve but can waste storage space. VARCHAR, a variable-length string, can be slower to store and retrieve but does not waste storage space. TEXT is a character BLOB that requires more storage space and I/O than the other two.

Can I change VARCHAR to TEXT MySQL?

There is no a big problem to change varchar to text because text supports more data length than varchar , but if the field has a index it must be drop and create new index with prefix col_name(length) (see CREATE INDEX syntax).

What does TEXT mean in MySQL?

TEXT is the family of column type intended as high-capacity character storage. The actual TEXT column type is of four types-TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT. The four TEXT types are very similar to each other; the only difference is the maximum amount of data each can store.


1 Answers

VARCHAR is probably preferable in your case from both the storage and performance perspective. View this oft-reposted article.

like image 100
LesterDove Avatar answered Oct 21 '22 21:10

LesterDove