What is the equivalent of varchar(max) in MySQL?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The max length of a varchar is subject to the max row size in MySQL, which is 64KB (not counting BLOBs):
However, note that the limit is lower if you use a multi-byte character set:
Here are some examples:
The maximum row size is 65535, but a varchar also includes a byte or two to encode the length of a given string. So you actually can’t declare a varchar of the maximum row size, even if it’s the only column in the table.
But if we try decreasing lengths, we find the greatest length that works:
Now if we try to use a multibyte charset at the table level, we find that it counts each character as multiple bytes. UTF8 strings don’t necessarily use multiple bytes per string, but MySQL can’t assume you’ll restrict all your future inserts to single-byte characters.
In spite of what the last error told us, InnoDB still doesn’t like a length of 21845.
This makes perfect sense, if you calculate that 21845*3 = 65535, which wouldn’t have worked anyway. Whereas 21844*3 = 65532, which does work.