MySQL - 行大小如何超过 65535

标签 mysql database database-design limit rows

据我所知,mysql 中的最大行限制是 65535,等于 (2 ^ 16) - 1。我也明白,像这样有非常长的行是糟糕的数据库设计。然而,这是我的架构

CREATE TABLE mytable(
  a VARCHAR(20000),
  b VARCHAR(20000),
  c VARCHAR(20000),
  d VARCHAR(5535)
) CHARACTER SET=latin1;

这是我得到的输出

Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs

再算一次

20000 + 20000 + 20000 + 5535 = 65535

等于且不超过限制。作为记录,d 列有效的最高值为 5526

我不明白那额外的 9 个字符是从哪里来的。

最佳答案

VARCHAR 的大小是这样计算的:

如果列为 0 – 255 字节,则 len + 1 字节;如果列可能需要超过 255 字节,则 len + 2 字节

所以

CREATE TABLE mytable(
  a VARCHAR(20000),       -- 20002
  b VARCHAR(20000),       -- 20002
  c VARCHAR(20000),       -- 20002
  d VARCHAR(5535)         --  5537
) CHARACTER SET=latin1;--    65543 !!!! 8 Bytes to much

看这个https://mariadb.com/kb/en/mariadb/data-type-storage-requirements/

关于MySQL - 行大小如何超过 65535,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34731211/

相关文章:

PHP/MySQL : How to modify working Select when the result is always one row

mysql - 如何使用 laravel Query Builder 进行复杂查询

mysql - 你会认为这是一个自然的主键吗?

mysql - 大量定时数据记录的数据库设计

javascript - 访问部分 javascript 数组 (mysqljs)

mysql - 如何连接到在azure中的linux虚拟机上运行的mysql服务器

android - 在我的数据库中添加数据时出错

sql - 如何在 postgresql 中创建 *swap 表(带/索引)

mysql - Sequelize : Performance advantage or just for convenience?

mysql - MySQL 是否允许使用直接连接的语法?