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

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

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

問題描述

限時送ChatGPT賬號..

當我執(zhí)行以下命令時:

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

我收到此錯誤消息:

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

關(guān)于 column1 和 column2 的信息:

Information about column1 and column2:

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

我認為 varchar(20) 只需要 21 個字節(jié),而 varchar(500) 只需要 501 個字節(jié).所以總字節(jié)數(shù)是 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 字節(jié)是 規(guī)定的前綴限制在 MySQL 5.6 版(和之前的版本)中的 InnoDB 表.MyISAM 表的長度為 1,000 字節(jié).在 MySQL 5.7 及更高版本中,此限制已增加到 3072 字節(jié).

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 字節(jié)(或 3072 字節(jié))的最大索引前綴長度除以 4,結(jié)果為 191.這是因為 utf8mb4 字符的最大長度是四個字節(jié).對于 utf8 字符,它將是三個字節(jié),導致最大索引前綴長度為 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.

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

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) );

調(diào)整,因為您需要獲取要應用的密鑰,但我想知道是否值得檢查有關(guān)此實體的數(shù)據(jù)模型,以查看是否有改進可以讓您在不影響 MySQL 的情況下實現(xiàn)預期的業(yè)務規(guī)則限制.

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.

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

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

相關(guān)文檔推薦

Typeorm Does not return all data(Typeorm 不返回所有數(shù)據(jù))
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉(zhuǎn)換為 mm/dd/yyyy?)
Incorrect syntax near #39;NVARCHAR#39;(“NVARCHAR附近的語法不正確)
Ms Sql convert varchar to Big Int(Ms Sql 將 varchar 轉(zhuǎn)換為 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 列的大小時會出現(xiàn)任何問題嗎?)
主站蜘蛛池模板: 欧美伊人久久久久久久久影院 | av毛片免费 | 国产精品九九视频 | 欧美一区二区三区在线视频 | 最新国产福利在线 | 成人不卡| 国产精品美女久久久av超清 | 国产精品自拍一区 | 精品国产乱码久久久久久影片 | 免费在线观看成人 | 日韩欧美精品在线播放 | 特黄视频 | 黑人巨大精品欧美一区二区一视频 | 中文字幕一区二区三区乱码图片 | 中文字幕一区二区三区精彩视频 | 日韩欧美在线视频 | 国产成人99久久亚洲综合精品 | 伊人网在线看 | 曰韩三级 | 国产精品1区 | 最新中文字幕一区 | 国产精品亚洲成在人线 | 香蕉久久a毛片 | 免费久久精品视频 | 精品国产青草久久久久96 | 精品香蕉一区二区三区 | 成人在线免费观看 | 精品国产成人 | 精品视频在线观看 | 日韩一区二区在线观看视频 | 青青久视频 | 国产91久久久久 | 中文字幕人成乱码在线观看 | 99re| 日本 欧美 三级 高清 视频 | 久久久久中文字幕 | 欧美亚洲视频 | 亚洲精品一区二区 | 国产成人区 | 在线一区二区国产 | 久草视频在线播放 |