問題
create table: Specified key was too long; max key length is 767 bytes
原因
數據庫表采用utf8編碼,其中varchar(255)的column進行了唯一鍵索引
而mysql默認情況下單個列的索引不能超過767位(不同版本可能存在差異)
於是utf8字符編碼下,255*3 byte 超過限制
解決
1 使用innodb引擎;
2 啟用innodb_large_prefix選項,將約束項擴展至3072byte;
3 重新創建數據庫;
my.cnf配置:
default-storage-engine=INNODB
innodb_large_prefix=on
一般情況下不建議使用這么長的索引,對性能有一定影響;
參考文檔:
