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;
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;
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
The above itself indicates -
The maximum row size is 65,535 bytes. If it exceeds, an error will be visible.
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!