Home > Database > Mysql Tutorial > What type is varchar in mysql?

What type is varchar in mysql?

王林
Release: 2020-06-28 09:21:18
Original
18272 people have browsed it

varchar in mysql is a variable-length type. In a varchar type data column, each value only occupies just enough bytes, plus one byte to record its length. If the maximum length of the string column is much larger than the average length, then varchar can be used to store it.

What type is varchar in mysql?

varchar type

(Recommended tutorial: mysql tutorial)

varchar is variable length Type: In a varchar(M) type data column, each value only occupies just enough bytes, plus a byte used to record its length (that is, the total length is L 1 byte).

Mysql adopts a fixed width for varchar fields in memory during query instead of variable width during storage, especially the invisible temporary table created during query. Therefore, when selecting field attributes, it is better to stop and choose the most appropriate and smallest length according to your own business, thereby improving the query speed and reducing the overhead of the database server.

When to use varchar column for storage?

1. The maximum length of the string column is much larger than the average length, giving full play to the characteristics of variable length;

2. The string column is rarely updated;

Because the storage page of the innodb engine is 16k, frequent updates of variable-length fields may cause the splitting of the storage page, resulting in storage fragmentation.

3. Multi-byte character set, such as utf-8;

The above is the detailed content of What type is varchar in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template