1. 程式人生 > >mysql索引欄位長度的問題

mysql索引欄位長度的問題

今天在做某網站列表頁的抓取的時候,對資料庫中列表頁URL欄位作了唯一性約束,免得還得自己手動進行排重,結果每次當插入重複的資料的時候,就出現了問題了,錯誤資訊如下:

    java.sql.SQLException: Incorrect key file for table './dianping/dianping_list_url.MYI'; try to repair it Query: INSERT IGNORE INTO dianping_list_ur
    at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:363)
    at org.apache.commons.dbutils.QueryRunner.batch(QueryRunner.java:154)
    at org.apache.commons.dbutils.QueryRunner.batch(QueryRunner.java:91)
    at com.umsg.db.Store.batch(Store.java:41)
    at com.umsg.db.Store$$EnhancerByCGLIB$$b856cba1.CGLIB$batch$0(<generated>)
    at com.umsg.db.Store$$EnhancerByCGLIB$$b856cba1$$FastClassByCGLIB$$82a71de6.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at com.umsg.db.StoreProxy.intercept(StoreProxy.java:42)
    at com.umsg.db.Store$$EnhancerByCGLIB$$b856cba1.batch(<generated>)
    at com.umsg.fetch.CrawlListPages.insertListUrls(CrawlListPages.java:268)
    at com.umsg.fetch.CrawlListPages.crawl(CrawlListPages.java:236)
    at com.umsg.fetch.CrawlListPages.main(CrawlListPages.java:542)

錯誤資訊顯示:表已經損壞了,因為之前我修改過表的型別,從MyISAM-->InnoDB,我以為是這塊出問題了,導致表壞了,但是把表drop掉,然後重新建表也不行,反正網上介紹的各種方法都試過了,什麼repair,myisamchk等命令都用過了。還是不行。

最後康老師說mysql索引的欄位的長度是有限制的。網上說不能超過1000,然後把url長度修改為128,程式順利跑了起來。

看來這個問題一定得引起注意,Mysql既然這麼做,需要防止索引檔案太大,導致查詢速度變慢。