久久久久久久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 字段上設(shè)置索引,則必須將 767 字節(jié)(或 3072 字節(jié))的最大索引前綴長度除以 4,結(jié)果為 191.這是因為 utf8mb4 字符的最大長度是四個字節(jié).對于 utf8 字符,它將是三個字節(jié),導(dǎo)致最大索引前綴長度為 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 字段設(shè)置下限.

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

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

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)整,因為您需要獲取要應(yīng)用的密鑰,但我想知道是否值得檢查有關(guān)此實體的數(shù)據(jù)模型,以查看是否有改進可以讓您在不影響 MySQL 的情況下實現(xiàn)預(yù)期的業(yè)務(wù)規(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)任何問題嗎?)
主站蜘蛛池模板: 成人精品视频99在线观看免费 | 一级免费毛片 | 国产精品成人一区二区 | 欧美日韩在线观看视频 | 欧美一级在线免费观看 | 欧美一极视频 | 婷婷色国产偷v国产偷v小说 | 国产福利在线看 | 福利精品在线观看 | 亚洲精品免费在线观看 | 中文字幕一区二区三区四区 | 狠狠的操| 一区精品视频 | 色偷偷噜噜噜亚洲男人 | 国产 欧美 日韩 一区 | 精品视频亚洲 | 91久久精品国产91久久 | 一区视频在线播放 | 成人免费淫片aa视频免费 | 免费人成激情视频在线观看冫 | av永久免费 | 国产日韩一区二区三区 | 日本精品久久久久久久 | 黄视频网址| 日韩在线视频一区 | 色悠悠久 | 久久久免费 | 国产精品网址 | 日日干夜夜操天天操 | 能看的av网站 | 在线成人 | 国产日韩欧美电影 | 亚洲成网| 国产精品一区二区视频 | 欧美一级二级在线观看 | 久久精品国产99国产精品亚洲 | 欧美日韩一区二区三区不卡视频 | 日韩欧美国产成人一区二区 | 国产伦一区二区三区 | 精品久久久久一区 | 一级毛片在线看 |