1. 程式人生 > 實用技巧 >mysql 資料庫執行建立索引語句異常 Specified key was too long; max key length is 767 bytes

mysql 資料庫執行建立索引語句異常 Specified key was too long; max key length is 767 bytes

Specified key was too long; max key length is 767 bytes

Index column size too large. The maximum column size is 767 bytes.

進入到mysql安裝資料庫目錄,找到my.cnf檔案

vi /etc/mysql/my.cnf

在[mysqld]下加入以下配置:

innodb_file_format=barracuda
innodb_file_per_table=true
innodb_large_prefix=true
character-set-server=utf8mb4
collation
-server=utf8mb4_unicode_ci max_allowed_packet=500M

修改後配置:

[mysqld]
user=mysql
# 字符集
character-set-server=utf8
default_authentication_plugin=mysql_native_password
#sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# 連線數
max_connections
=1500 # 不區分大小寫 lower_case_table_names=1 # 解決問題 maximum column size is 767 bytes. innodb_file_format=barracuda innodb_file_per_table=true innodb_large_prefix=true character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci max_allowed_packet=500M [client] default-character-set=utf8 [mysql] default-character-set
=utf8

重啟資料庫。

再次執行指令碼。