日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql blob key length_mysql提示used in key specification without a key length

發(fā)布時(shí)間:2023/12/15 数据库 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql blob key length_mysql提示used in key specification without a key length 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

今天最火軟件站小編在寫一個(gè)PHP小東西的時(shí)候遇到了一個(gè)問題,設(shè)計(jì)數(shù)據(jù)庫(kù)類型的時(shí)候提示:xxxx used in key specification without a key length,百思不得其解,后來在網(wǎng)上找到關(guān)于這個(gè)問題的答案。

原來Mysql數(shù)據(jù)庫(kù)對(duì)于BLOB/TEXT這樣類型的數(shù)據(jù)結(jié)構(gòu)只能索引前N個(gè)字符。所以這樣的數(shù)據(jù)類型不能作為主鍵,也不能是UNIQUE的。所以要換成VARCH,但是VARCHAR類型的大小也不能大于255,當(dāng)VARCHAR類型的字段大小如果大于255的時(shí)候也會(huì)轉(zhuǎn)換成小的TEXT來處理。所以也同樣有問題。

官方的英文解釋如下:

The?error?happens?because?MySQL?can?index?only?the?first?N?chars?of?a?BLOB?or?TEXT?column.?So?The?error?mainly?happen?when?there?is?a?field/column?type?of?TEXT?or?BLOB?or?those?belongs?to?TEXT?or?BLOB?types?such?as?TINYBLOB,?MEDIUMBLOB,?LONGBLOB,?TINYTEXT,?MEDIUMTEXT,?and?LONGTEXT?that?you?try?to?make?as?primary?key?or?index.?With?full?BLOB?or?TEXT?without?the?length?value,?MySQL?is?unable?to?guarantee?the?uniqueness?of?the?column?as?it’s?of?variable?and?dynamic?size.?So,?when?using?BLOB?or?TEXT?types?as?index,?the?value?of?N?must?be?supplied?so?that?MySQL?can?determine?the?key?length.?However,?MySQL?doesn’t?support?a?key?length?limit?on?TEXT?or?BLOB.?TEXT(88)?simply?won’t?work.

The?error?will?also?pop?up?when?you?try?to?convert?a?table?column?from?non-TEXT?and?non-BLOB?type?such?as?VARCHAR?and?ENUM?into?TEXT?or?BLOB?type,?with?the?column?already?been?defined?as?unique?constraints?or?index.?The?Alter?Table?SQL?command?will?fail.

The?solution?to?the?problem?is?to?remove?the?TEXT?or?BLOB?column?from?the?index?or?unique?constraint,?or?set?another?field?as?primary?key.?If?you?can’t?do?that,?and?wanting?to?place?a?limit?on?the?TEXT?or?BLOB?column,?try?to?use?VARCHAR?type?and?place?a?limit?of?length?on?it.?By?default,?VARCHAR?is?limited?to?a?maximum?of?255?characters?and?its?limit?must?be?specified?implicitly?within?a?bracket?right?after?its?declaration,?i.e?VARCHAR(200)?will?limit?it?to?200?characters?long?only.

Sometimes,?even?though?you?don’t?use?TEXT?or?BLOB?related?type?in?your?table,?the?Error?1170?may?also?appear.?It?happens?in?situation?such?as?when?you?specify?VARCHAR?column?as?primary?key,?but?wrongly?set?its?length?or?characters?size.?VARCHAR?can?only?accepts?up?to?256?characters,?so?anything?such?as?VARCHAR(512)?will?force?MySQL?to?auto-convert?the?VARCHAR(512)?to?a?SMALLTEXT?datatype,?which?subsequently?fail?with?error?1170?on?key?length?if?the?column?is?used?as?primary?key?or?unique?or?non-

總結(jié)

以上是生活随笔為你收集整理的mysql blob key length_mysql提示used in key specification without a key length的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。