bitsCN.com
[MySQL 错误]ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not解决
朋友发过来一个SQL,,让我执行以下:CREATE TABLE `ttt` ( `id` DOUBLE , `select_type` VARCHAR (57), `table` VARCHAR (192), `type` VARCHAR (30), `possible_keys` VARCHAR (22288), `key` VARCHAR (192), `key_len` VARCHAR (22288), `ref` VARCHAR (3072), `rows` DOUBLE , `Extra` VARCHAR (765) ); INSERT INTO `ttt` (`id`, `select_type`, `table`, `type`, `possible_keys`, `key`, `key_len`, `ref`, `rows`, `Extra`) VALUES('1','PRIMARY','aaa','index',NULL,'email_2','51',NULL,'5','Using where; Using index'); INSERT INTO `ttt` (`id`, `select_type`, `table`, `type`, `possible_keys`, `key`, `key_len`, `ref`, `rows`, `Extra`) VALUES('2','DEPENDENT SUBQUERY','bbb','ref','id','id','5','test.aaa.id','1','Using where; Using index'); 执行第一句建表的时候就卡住了,报错如下:mysql> CREATE TABLE `ttt` ( -> `id` DOUBLE , -> `select_type` VARCHAR (57), -> `table` VARCHAR (192), -> `type` VARCHAR (30), -> `possible_keys` VARCHAR (12288), -> `key` VARCHAR (192), -> `key_len` VARCHAR (12288), -> `ref` VARCHAR (3072), -> `rows` DOUBLE , -> `Extra` VARCHAR (765) -> ); ERROR 1118 (42000): 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 mysql> 看了提示,表的2个varchar字段长度设置过长了,需要改成text,blob之类的类型,修改之后执行成功了:mysql> use test; Database changed mysql> mysql> CREATE TABLE `ttt` ( -> `id` DOUBLE , -> `select_type` VARCHAR (57), -> `table` VARCHAR (192), -> `type` VARCHAR (30), -> `possible_keys` TEXT, -> `key` VARCHAR (192), -> `key_len` TEXT, -> `ref` VARCHAR (3072), -> `rows` DOUBLE , -> `Extra` VARCHAR (765) -> ); Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO `ttt` (`id`, `select_type`, `table`, `type`, `possible_keys`, `key`, `key_len`, `ref`, `rows`, `Extra`) VALUES('1','PRIMARY','aaa','index',NULL,'email_2','51',NULL,'5','Using where; Using index'); Query OK, 1 row affected (0.04 sec) mysql> INSERT INTO `ttt` (`id`, `select_type`, `table`, `type`, `possible_keys`, `key`, `key_len`, `ref`, `rows`, `Extra`) VALUES('2','DEPENDENT SUBQUERY','bbb','ref','id','id','5','test.aaa.id','1','Using where; Using index'); Query OK, 1 row affected (0.00 sec) mysql> select * from ttt; +------+--------------------+-------+-------+---------------+---------+---------+-------------+------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+--------------------+-------+-------+---------------+---------+---------+-------------+------+--------------------------+ | 1 | PRIMARY | aaa | index | NULL | email_2 | 51 | NULL | 5 | Using where; Using index | | 2 | DEPENDENT SUBQUERY | bbb | ref | id | id | 5 | test.aaa.id | 1 | Using where; Using index | +------+--------------------+-------+-------+---------------+---------+---------+-------------+------+--------------------------+ 2 rows in set (0.00 sec)
疑惑:varchar(N),这个N不是最大为65535吗?为什么设置成12288就会报错?12288比65535小很多啊。
有问题上官网:http://dev.mysql.com/doc/refman/5.6/en/char.html
In contrast to CHAR, VARCHAR values are stored as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.
原来有N有255这样一个坎啊,超过了N的意义就不一样了。
后续测试1 ,朋友木木说是字符集的问题,那么我就执行之前设置下字符集,不过还是报错,但是我在SQLyog工具的窗口里面执行是成功(工具里面自动转变成mediumtext类型了)。
mysql> set names utf8; Query OK, 0 rows affected (0.00 sec) mysql> DROP TABLE ttt; ERROR 1051 (42S02): Unknown table 'test.ttt' mysql> CREATE TABLE `ttt` ( -> `id` DOUBLE , -> `select_type` VARCHAR (57), -> `table` VARCHAR (192), -> `type` VARCHAR (65535), -> `key` VARCHAR(20), -> `possible_keys` VARCHAR (100), -> `key_len` VARCHAR (65535), -> `ref` VARCHAR (11), -> `rows` DOUBLE , -> `Extra` VARCHAR (765) -> ); ERROR 1074 (42000): Column length too big for column 'type' (max = 21845); use BLOB or TEXT instead mysql> set names gbk; Query OK, 0 rows affected (0.00 sec) mysql> DROP TABLE ttt; ERROR 1051 (42S02): Unknown table 'test.ttt' mysql> CREATE TABLE `ttt` ( -> `id` DOUBLE , -> `select_type` VARCHAR (57), -> `table` VARCHAR (192), -> `type` VARCHAR (65535), -> `key` VARCHAR(20), -> `possible_keys` VARCHAR (100), -> `key_len` VARCHAR (65535), -> `ref` VARCHAR (11), -> `rows` DOUBLE , -> `Extra` VARCHAR (765) -> ); ERROR 1074 (42000): Column length too big for column 'type' (max = 21845); use BLOB or TEXT instead mysql>
最后总结:这个可能是超过 一个表 关于 非十六进制字段 64k的限制了。
上官网:http://dev.mysql.com/doc/refman/5.5/en/column-count-limit.html:
Every table (regardless of storage engine) has a maximum row size of 65,535 bytes. Storage engines may place additional constraints on this limit, reducing the effective maximum row size.
65,535所说明的是针对的是整个表的非大字段类型的字段的bytes总合。
bitsCN.com
The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool