MySQL error: The maximum column size is 767 bytes

前端 未结 10 1767
陌清茗
陌清茗 2020-12-24 15:41

When I run a program which does something with MySQL, I got this error message:

2015-06-10 15:41:12,250 ERROR app.wsutils 419 INCRON: Error: (\'HY000\

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 16:19

    I had the same error despite having innodb_large_prefix configured correctly.

    The issue was in used collation. My db had default collation set to utf8mb4_bin (you can check it in phpmyadmin "Operations" tab for database). It means it uses 4 bytes per char, while utf8 collation (e.g. utf8_unicode_ci) uses 3 bytes per char.

    in this case you can either use different collation e.g. by adding DEFAULT CHARSET=utf8 at the end of the CREATE TABLE statement, or limit the index size by using just a part of the column value like KEY 'identifier' (column1(5),column2(10)).

    See also related question: #1071 - Specified key was too long; max key length is 767 bytes

提交回复
热议问题