mysql 报错 Specified key was too long; max key length is 767 bytes,开启系统变量:innodb_large_prefix
生活随笔
收集整理的這篇文章主要介紹了
mysql 报错 Specified key was too long; max key length is 767 bytes,开启系统变量:innodb_large_prefix
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
mysql 報錯 Specified key was too long; max key length is 767 bytes
當mysql數據庫的字符集使用了utf8mb4,就很容易在執行建表sql的時候報這個錯誤。
原因:
mysql有個系統變量innodb_large_prefix,
如果開啟了,索引鍵前綴限制為3072字節;
如果禁用了,索引鍵前綴限制為767字節。
當mysql數據庫的字符集使用了utf8mb4,每個字符最大的字節數為4,如果建表語句中,有類似varchar(255)的字段,4*255 > 767,就會報這個錯: Specified key was too long; max key length is 767 bytes。
解決:
方法1:varchar(x),x<191,那么4*x<767,就不會報錯。
方法2:開啟系統變量:innodb_large_prefix,如下操作:
mysql> set global innodb_file_format = BARRACUDA; Query OK, 0 rows affected (0.00 sec)mysql> set global innodb_large_prefix = ON; Query OK, 0 rows affected (0.00 sec)總結
以上是生活随笔為你收集整理的mysql 报错 Specified key was too long; max key length is 767 bytes,开启系统变量:innodb_large_prefix的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 改进初学者的PID-手自动切换
- 下一篇: 关于数据库备份的问题