将表从 latin1 转换为 UTF-8,键太大问题
我正在尝试将一些数据库表从 latin1 字符集转换为 utf-8。许多表转换得很好,但有些表返回此错误:
alter table xyz Convert to CHARACTER SET utf8; 错误 1118 (42000):行大小太大。所用表类型的最大行大小(不包括 BLOB)为 65535。您必须将某些列更改为 TEXT 或 BLOB
有解决方法吗?为了顺利进行转换,表中的最小长度列大小应该是多少?另外,如何在不破坏表中数据的情况下更改需要更改的列?
顺便说一句,这是表格。
mysql> describe trailheads;
+-----------------------+----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+----------------+------+-----+---------+----------------+
| trailhead_id | int(10) | NO | PRI | NULL | auto_increment |
| trail_id | int(10) | YES | | NULL | |
| park_id | int(10) | YES | | NULL | |
| editor_member_id | int(10) | NO | | NULL | |
| trailhead_name | varchar(1000) | NO | | NULL | |
| trailhead_description | varchar(20000) | YES | | NULL | |
| parking | tinyint(1) | YES | | NULL | |
| parking_spots | int(5) | YES | | NULL | |
| is_free | tinyint(1) | YES | | NULL | |
| cost_details | varchar(5000) | YES | | NULL | |
| lat | float(9,6) | NO | | NULL | |
| lng | float(9,6) | NO | | NULL | |
| bathrooms_nearby | tinyint(1) | YES | | NULL | |
| wheelchair_accessible | tinyint(1) | YES | | NULL | |
| date_added | date | NO | | NULL | |
| last_edit_date | date | YES | | NULL | |
+-----------------------+----------------+------+-----+---------+----------------+
I am trying to convert some of my DB tables from latin1 character set to utf-8. Many tables got converted fine, but some tables return this error:
alter table xyz convert to CHARACTER SET utf8;
ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs
Is there a work around for this? What is the min length column sizes I should have in the tables for the conversion to take place without problems? And also, how can I alter the columns that I need to alter without breaking the data in the table?
Here is the table by the way.
mysql> describe trailheads;
+-----------------------+----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+----------------+------+-----+---------+----------------+
| trailhead_id | int(10) | NO | PRI | NULL | auto_increment |
| trail_id | int(10) | YES | | NULL | |
| park_id | int(10) | YES | | NULL | |
| editor_member_id | int(10) | NO | | NULL | |
| trailhead_name | varchar(1000) | NO | | NULL | |
| trailhead_description | varchar(20000) | YES | | NULL | |
| parking | tinyint(1) | YES | | NULL | |
| parking_spots | int(5) | YES | | NULL | |
| is_free | tinyint(1) | YES | | NULL | |
| cost_details | varchar(5000) | YES | | NULL | |
| lat | float(9,6) | NO | | NULL | |
| lng | float(9,6) | NO | | NULL | |
| bathrooms_nearby | tinyint(1) | YES | | NULL | |
| wheelchair_accessible | tinyint(1) | YES | | NULL | |
| date_added | date | NO | | NULL | |
| last_edit_date | date | YES | | NULL | |
+-----------------------+----------------+------+-----+---------+----------------+
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能是
trailhead_description
字段。在较新的 mySQL 版本中,
VARCHAR
字段长度表示最大字符数而不是字节。由于 UTF-8 字符最多可达 4 个字节长,因此 20,000 个字符的
VARCHAR
可能最多需要 80,000 个字节 - 显然超出了最大限制。将该列更改为
TEXT
应该可以。The problem is probably the
trailhead_description
field.In newer mySQL versions, the
VARCHAR
field length denotes the maximum number of characters as opposed to bytes.Because a UTF-8 character can be up to four bytes long, a 20,000 character
VARCHAR
might take up to 80,000 bytes - clearly beyond the maximum limit.Changing that column to
TEXT
should work.