What is the maximum size of a MySQL VARCHAR?

王林
Release: 2023-09-06 08:05:07
forward
1810 people have browsed it

MySQL VARCHAR 最大大小是多少?

MySQL before version 5.0.3 could store 255 characters, but starting from version 5.0.3, it can store 65,535 characters.

MySQL official documentation states:

The effective maximum length of VARCHAR in MySQL 5.0.3 and later depends on the maximum row size (65,535 bytes, which is shared by all columns) and all The character set used. For example, utf8 characters may require up to three bytes per character, so a VARCHAR column using the utf8 character set can be declared to have a maximum of 21,844 characters.

Remember that the maximum row size limit is 65,535 bytes. This means that including all columns, the total size should not exceed 65,535 bytes.

Let's see what happens if this limit is violated:

This is a table with two columns, "one" is a varchar of length 32,765 and "two" is a varchar of length 32,766 varchar.

Length = 32765 2 32766 2 = 65535.

CREATE TABLE IF NOT EXISTS `mytable` ( `one` varchar(32765) NOT NULL, `two` varchar(32766) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Copy after login

Now let us increase the column length -

CREATE TABLE IF NOT EXISTS `mytable` ( `one` varchar(32767) NOT NULL, `two` varchar(32770) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Copy after login

The above gives the following error -

#1118 - Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs
Copy after login

The above itself indicates -

The maximum row size is 65,535 bytes. If it exceeds, an error will be visible.
Copy after login

The above is the detailed content of What is the maximum size of a MySQL VARCHAR?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!