patternsqlMinor
MySQL varchar(255) limitation & Anomaly
Viewed 0 times
255varcharanomalymysqllimitation
Problem
I have defined a column in my MySQL database as :
However, when I enter text that is longer than 233 characters from my front end the data is truncated.
Changing the size of the column to varchar(511) has made no difference.
I counted the number of characters using PHP's
Why is MySQL doing this, and how can I save the full string?
ALTER TABLE `my_table` CHANGE `desc` `desc` VARCHAR( 255 )
CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULLHowever, when I enter text that is longer than 233 characters from my front end the data is truncated.
Changing the size of the column to varchar(511) has made no difference.
I counted the number of characters using PHP's
strlen() function and it revealed 233 characters.Why is MySQL doing this, and how can I save the full string?
Solution
MySQL is not cutting it at 233. The problem is likely in your save method which cuts it to 233 before the data even reaches MySQL.
Also, don't forget that 233 limit is not character limit, and as some character might need more han 1 byte to be stored, you might see less than 233 characters.
Also please make sure that data in MySQL server is really stored as latin1, this can be accomplished with:
Also, don't forget that 233 limit is not character limit, and as some character might need more han 1 byte to be stored, you might see less than 233 characters.
Also please make sure that data in MySQL server is really stored as latin1, this can be accomplished with:
show variables like 'char%';Code Snippets
show variables like 'char%';Context
StackExchange Database Administrators Q#25254, answer score: 2
Revisions (0)
No revisions yet.