Varchar and text note in Mysql

Source: Internet
Author: User

In Mysql, varchar and text note Varchar occupy two bytes for each English (ASCII) character, and one Chinese character only occupies two bytes for char and one English (ASCII) character, the type of a Chinese character that occupies 2 bytes of Varchar is not filled with spaces, for example, varchar (100), but its value is only "n ", then its value is "n" and char is different, for example, char (100), its value is "n ", in fact, it is "n" in the database (there are 99 spaces after n, that is, it is filled with 100 bytes ). Char is of a fixed length, so it is much faster than varchar! However, it is a little troublesome for the program to process it. We need to use functions such as trim to remove spaces on both sides! Note that for the encoded char (N)/varchar (N), N indicates the maximum number of characters allowed in the current column. not the number of bytes. the text type can be divided into tinytext (255 length), smalltext (65535), midumtext (int maximum), and longtext (long maximum ). in mysql, the storage of text data is somewhat different from that of varchar/char. text data is stored outside the metadata table, however, varchar/char is stored in the table data file together with other columns. in fact, the text data type will greatly increase the size of the database table file, which has some impact on physical storage. Meanwhile, text data retrieval and IO output will also increase competition for memory. most of the time, we recommend that you store the text type, especially the data with a large length or frequent changes, on other proprietary platforms, such as NOSQL .. in essence, mysql is not suitable for text storage, but in many cases, we expect mysql to provide more efficient small data query/transaction processing.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.