MySQL是一个开放源码的小型关联式数据库管理系统,是Discuz!论坛首选的数据库。目前MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。MySQL数据库由于某种原因造成表的损坏,就需要我们人工修复了。
我们的网站是用Discuz!论坛源码搭建的,今天登录网站后台就出现错误,提示如下:
Discuz! Database Error (1194) Table 'forum_post' is marked as crashed and should be repaired SELECT * FROM forum_post WHERE 1 AND `invisible`='-5' ORDER BY dateline DESC LIMIT 20 PHP Debug No. File Line Code 1 admin.php 57 require(%s) 2 source/admincp/admincp_recyclebinpost.php 67 recyclebinpostshowpostlist(%s, %s, %s, %s, %s, %d, %d) 3 source/admincp/admincp_recyclebinpost.php 213 table_forum_post->fetch_all_by_search(%d, %s, %s, %d, %s, %s, %s, false, false, %s, %s, %d, %d) 4 source/class/table/table_forum_post.php 709 discuz_database::fetch_all(%s, Array) 5 source/class/discuz/discuz_database.php 100 discuz_database::query(%s, Array, false, false) 6 source/class/discuz/discuz_database.php 136 db_driver_mysql->query(%s, false, false) 7 source/class/db/db_driver_mysql.php 153 db_driver_mysql->halt(%s, %d, %s) 8 source/class/db/db_driver_mysql.php 224 break()
很显然这是数据库中表forum_post已经损坏,需要我们修复。为了修复MySQL,很自然想到PhpMyAdmin傻瓜式的修复数据库。很遗憾,我们网站的数据库达到数十个G,PhpMyAdmin修复时总是提示超时,无能为力了。
那么怎么办呢?我查询网上的资料,共有3中可行方法:
myisamchk --recover --quick tablename myisamchk --recover tablename myisamchk --safe-recover tablename
第一种是最快的,用来修复最普通的问题;而最后一种是最慢的,用来修复一些其它方法所不能修复的问题。
下面就用上述方法修复,用SSH登录网站服务器,用最快的方法(myisamchk –recover –quick pre_forum_post)修复看看。
[root@localhost discuz]# myisamchk --recover --quick pre_forum_post - check record delete-chain - recovering (with sort) MyISAM-table 'pre_forum_post' Data records: 0 - Fixing index 1 Key 1 - Found wrong stored record at 9555086764 MyISAM-table 'pre_forum_post' is not fixed because of errors Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag
上述方法修复MySQL数据库出错了,但是提示我们用–safe-recover (-o), the –force (-f) option or by not using the –quick (-q) flag。既然这样,我们就用选项–safe-recover (-o)吧,即第三种方法:myisamchk –safe-recover pre_forum_post。
[root@localhost discuz]# myisamchk --safe-recover pre_forum_post - recovering (with keycache) MyISAM-table 'pre_forum_post' Data records: 9688000 Key 1 - Found wrong stored record at 9555086764 Key 1 - Found wrong stored record at 10789444844 Data records: 10749181
上述方法虽然最慢,但我们的问题解决了,MySQL数据库圆满修复。Discuz!论坛打开完全正常,哈哈~