Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

sql - Mysql 1406 Data too long for column

I have a string containing more than 600 characters, where I want to Insert it in a column VARCHAR (255) column
I tested on two different databases:

  1. For a mysql 5.7.31-34-log database, I ran into this exception:
    SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'name' at row 1"
  • I dumped the sql_mode for each database and this the result:

["@@sql_mode"]=> string(40) "STRICT_ALL_TABLES,NO_ENGINE_SUBSTITUTION"

  1. On the other hand for a mysql 5.7.19 database, the string is well registered into my database, but with a warning message: Level Code Message
    Warning 1265 Data truncated for column 'name' at row 1
  • sql_mode:

["@@sql_mode"]=> string(0) ""

I would be grateful if someone could explain to me it is a good practice to disable strict mode, and does truncate remove a part of the string if exceeded ?

question from:https://stackoverflow.com/questions/66059735/mysql-1406-data-too-long-for-column

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you cannot store 600 character in varchar(255) since It's allowing only 255 character.dependingvon your configuration data will be rejected or truncated after 255 character. The version of MySql you are using allow way more that 255 for varchar data type. please alter the column to extend the length. you may use varchar(600) for example.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...