久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

MySQL 錯誤 #1071 - 指定的鍵太長;最大密鑰長度為

MySQL Error #1071 - Specified key was too long; max key length is 767 bytes(MySQL 錯誤 #1071 - 指定的鍵太長;最大密鑰長度為 767 字節)
本文介紹了MySQL 錯誤 #1071 - 指定的鍵太長;最大密鑰長度為 767 字節的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

當我執行以下命令時:

ALTER TABLE `mytable` ADD UNIQUE (
`column1` ,
`column2`
);

我收到此錯誤消息:

#1071 - Specified key was too long; max key length is 767 bytes

關于 column1 和 column2 的信息:

Information about column1 and column2:

column1 varchar(20) utf8_general_ci
column2  varchar(500) utf8_general_ci

我認為 varchar(20) 只需要 21 個字節,而 varchar(500) 只需要 501 個字節.所以總字節數是 522,小于 767.那么為什么我會收到錯誤消息?

I think varchar(20) only requires 21 bytes while varchar(500) only requires 501 bytes. So the total bytes are 522, less than 767. So why did I get the error message?

#1071 - Specified key was too long; max key length is 767 bytes

推薦答案

767 字節是 規定的前綴限制在 MySQL 5.6 版(和之前的版本)中的 InnoDB 表.MyISAM 表的長度為 1,000 字節.在 MySQL 5.7 及更高版本中,此限制已增加到 3072 字節.

767 bytes is the stated prefix limitation for InnoDB tables in MySQL version 5.6 (and prior versions). It's 1,000 bytes long for MyISAM tables. In MySQL version 5.7 and upwards this limit has been increased to 3072 bytes.

您還必須注意,如果您在 utf8mb4 編碼的 big char 或 varchar 字段上設置索引,則必須將 767 字節(或 3072 字節)的最大索引前綴長度除以 4,結果為 191.這是因為 utf8mb4 字符的最大長度是四個字節.對于 utf8 字符,它將是三個字節,導致最大索引前綴長度為 254.

You also have to be aware that if you set an index on a big char or varchar field which is utf8mb4 encoded, you have to divide the max index prefix length of 767 bytes (or 3072 bytes) by 4 resulting in 191. This is because the maximum length of a utf8mb4 character is four bytes. For a utf8 character it would be three bytes resulting in max index prefix length of 254.

您可以選擇的一種方法是為您的 VARCHAR 字段設置下限.

One option you have is to just place lower limit on your VARCHAR fields.

另一種選擇(根據對此問題的回應)是獲得列的子集而不是整個金額,即:

Another option (according to the response to this issue) is to get the subset of the column rather than the entire amount, i.e.:

ALTER TABLE `mytable` ADD UNIQUE ( column1(15), column2(200) );

調整,因為您需要獲取要應用的密鑰,但我想知道是否值得檢查有關此實體的數據模型,以查看是否有改進可以讓您在不影響 MySQL 的情況下實現預期的業務規則限制.

Tweak as you need to get the key to apply, but I wonder if it would be worth it to review your data model regarding this entity to see if there's improvements that would allow you to implement the intended business rules without hitting the MySQL limitation.

這篇關于MySQL 錯誤 #1071 - 指定的鍵太長;最大密鑰長度為 767 字節的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Typeorm Does not return all data(Typeorm 不返回所有數據)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉換為 mm/dd/yyyy?)
Incorrect syntax near #39;NVARCHAR#39;(“NVARCHAR附近的語法不正確)
Ms Sql convert varchar to Big Int(Ms Sql 將 varchar 轉換為 Big Int)
UNDOCUMENTED FEATURE when SELECT in VARCHAR with trailing whitespace SQL Server(在 VARCHAR 中使用尾隨空格 SQL Server SELECT 時的未記錄功能)
When increasing the size of VARCHAR column on a large table could there be any problems?(在大表上增加 VARCHAR 列的大小時會出現任何問題嗎?)
主站蜘蛛池模板: 国产精品国产三级国产a | 成人伊人 | 久久1区 | 国产精品五月天 | 亚洲国产一区在线 | 高清视频一区 | 激情a| 欧美精品一区二区三区在线播放 | 国产高清精品网站 | 成人国产精品一级毛片视频毛片 | 亚洲一区二区三区四区在线观看 | 成人av色 | 亚洲三区在线 | 欧美在线视频一区 | 99精品99| 国产精品久久久久无码av | 久久成人免费视频 | 羞羞的视频在线观看 | 久久综合一区二区三区 | 黄a免费网络 | 91网视频| 日韩av.com | 欧美在线 | 能看的av | 欧美日韩精品久久久免费观看 | 欧美一区成人 | 亚洲大片一区 | 亚洲欧美日韩国产综合 | 看片地址 | 一区二区三区视频在线观看 | 亚洲一区二区在线播放 | 国产精品片aa在线观看 | 久久久不卡网国产精品一区 | 亚洲免费在线视频 | 性在线 | 免费观看国产视频在线 | 中文字幕欧美日韩一区 | 欧美狠狠操| 日本成人中文字幕在线观看 | 成人毛片视频免费 | 亚洲综合天堂 |