今天在做某网站列表页的抓取的时候,对数据库中列表页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()
at com.umsg.db.store$$enhancerbycglib$$b856cba1$$fastclassbycglib$$82a71de6.invoke()
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()
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既然这么做,需要防止索引文件太大,导致查询速度变慢。