数据库表迁移遇到问题
创建表时报错
ERROR 1118 (42000): Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.
原因
创建表时有390个字段,其中可能有很多 varchar(255)的默认值;
一条记录太长,超过了8126字节,建议部分列使用text或blob类型
官方文档的描述:
【The MySQL maximum row size limit of 65,535 bytes is demonstrated in the following InnoDB and MyISAM examples. The limit is enforced regardless of storage engine, even though the storage engine may be capable of supporting larger rows.】
在MYSQL数据库中一条记录的最大长度是65535字节,以下以Innodb和mysiam存储引擎为例,做了相关演示,不管任何存储引擎,都不能超过这个范围,即存储引擎支持一行存储更长的数据。
【InnoDB restricts row size (for data stored locally within the database page) to slightly less than half a database page for 4KB, 8KB, 16KB, and 32KB innodb_page_size settings, and to slightly less than 16KB for 64KB pages.】
Inodb存储引擎,对于4K,8K,16K和32K的页面大小,限制一条记录最多使用半个页面,,64K页面比16KB页面限制稍小一些。
解决
分情况解决
字段不是很多,不跟我一样字段390个
可以修改字段的长度大小,比如varchar(255)修改成varchar(30);
或者将大的varchar字段类型修改为 text类型或blob类型
字段过多
如果上面解决方法不行,那有可能是字段过多,需要修改mysql的配置文件
我这用的mysql5.7版本
第一步,Win+R 弹出运行窗口,输入 regedit 打开注册表
第二步,依次打开:HKEY_LOCAL_MACHINE–>SYSTEM–>CurrentControlSet–>Services–>MySQL57,找到 ImagePath
双击打开,才能看到MySQL配置文件的真正路径
第三步,修改mysql.ini文件
在 [mysqld] 下添加
innodb_log_file_size = 512
innodb_strict_mode = 0
第四步,重启mysql就可以了