問題
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