“Data too long for column” - why?

前端 未结 12 699
Happy的楠姐
Happy的楠姐 2020-12-12 19:47

I\'ve written a MySQL script to create a database for hypothetical hospital records and populate it with data. One of the tables, Department, has a column named Description,

12条回答
  •  我在风中等你
    2020-12-12 20:20

    There is an hard limit on how much data can be stored in a single row of a mysql table, regardless of the number of columns or the individual column length.

    As stated in the OFFICIAL DOCUMENTATION

    The maximum row size constrains the number (and possibly size) of columns because the total length of all columns cannot exceed this size. For example, utf8 characters require up to three bytes per character, so for a CHAR(255) CHARACTER SET utf8 column, the server must allocate 255 × 3 = 765 bytes per value. Consequently, a table cannot contain more than 65,535 / 765 = 85 such columns.

    Storage for variable-length columns includes length bytes, which are assessed against the row size. For example, a VARCHAR(255) CHARACTER SET utf8 column takes two bytes to store the length of the value, so each value can take up to 767 bytes.

    Here you can find INNODB TABLES LIMITATIONS

提交回复
热议问题