解决 MySQL 的 Table is marked as crashed and should be repaired 问题

昨天一位 VPS 客户说他的 WordPress 博客没了,网站可以打开,但是文章都没了,怀疑被黑。我们登陆客户 VPS 后没发现被黑迹象,然后进入 MySQL 数据库发现 Table ‘./wordpress/wp_posts’ is marked as crashed and should be repaired 错误,因为 wp_posts 表被损坏了,所以 WordPress 的文章都显示不出来:

# mysql -u root -p
Enter password:

mysql> use wordpress;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from wp_posts;
ERROR 145 (HY000): Table './wordpress/wp_posts' is marked as crashed and should be repaired
mysql> Bye

修复 MySQL 数据库数据表问题可以由 mysqlcheck 来解决,先用 mysqlcheck 查看一下:

# mysqlcheck -u root -p wordpress
Enter password:

然后添加 –auto-repair 参数自动修复,最好修复前备份一下数据库:

# mysqldump -u root -p wordpress > wordpress.sql
Enter password:

# mysqlcheck -u root -p wordpress --auto-repair
Enter password:
wordpress.wp_commentmeta
error    : Table upgrade required. Please do "REPAIR TABLE `wp_commentmeta`" or dump/reload to fix it!
wordpress.wp_comments
error    : Table upgrade required. Please do "REPAIR TABLE `wp_comments`" or dump/reload to fix it!
wordpress.wp_links
error    : Table upgrade required. Please do "REPAIR TABLE `wp_links`" or dump/reload to fix it!
wordpress.wp_options
error    : Table upgrade required. Please do "REPAIR TABLE `wp_options`" or dump/reload to fix it!
wordpress.wp_postmeta
error    : Table upgrade required. Please do "REPAIR TABLE `wp_postmeta`" or dump/reload to fix it!
wordpress.wp_posts
error    : Table upgrade required. Please do "REPAIR TABLE `wp_posts`" or dump/reload to fix it!
wordpress.wp_term_relationships                OK
wordpress.wp_term_taxonomy
error    : Table upgrade required. Please do "REPAIR TABLE `wp_term_taxonomy`" or dump/reload to fix it!
wordpress.wp_terms
error    : Table upgrade required. Please do "REPAIR TABLE `wp_terms`" or dump/reload to fix it!
wordpress.wp_usermeta
error    : Table upgrade required. Please do "REPAIR TABLE `wp_usermeta`" or dump/reload to fix it!
wordpress.wp_users
error    : Table upgrade required. Please do "REPAIR TABLE `wp_users`" or dump/reload to fix it!

Repairing tables
wordpress.wp_commentmeta                       OK
wordpress.wp_comments                          OK
wordpress.wp_links                             OK
wordpress.wp_options                           OK
wordpress.wp_postmeta                          OK
wordpress.wp_posts                             OK
wordpress.wp_term_taxonomy                     OK
wordpress.wp_terms                             OK
wordpress.wp_usermeta                          OK
wordpress.wp_users                             OK

评论 (8 Comments)

  1. 老大服务真到位啊,这样问题还帮看,不错,佩服,够敬业!!!!

  2. 嘿嘿,我的,我的:)感谢迅速、专业地解决问题,多谢!

  3. 不错!!

    再请教一个问题:
    怎么查看XEN HOST的物理CPU个数、核心数量、内存、硬盘等信息?
    我在DOM0下执行cat /proc/cpuinfo |grep physical\ id|sort|uniq命令和cat /proc/cpuinfo |grep cpu\ cores|uniq

    显示信息好像不太对。。

  4. @ccr
    可以使用 xm info, xm top 等得到真实 CPU、内存等信息。

  5. 谢谢。

    我的物理机器的CPU是1 颗个Intel(R) Xeon(R) CPU E5620 @ 2.40GHz,4核心的

    请问xm info里的物理CPU数量是怎么计算的??好像只有逻辑的数量
    [[email protected] ~]# xm info
    host : vps
    release : 2.6.18-274.12.1.AV2.el5xen
    version : #1 SMP Tue Dec 13 11:12:17 MST 2011
    machine : x86_64
    nr_cpus : 8
    nr_nodes : 1
    cores_per_socket : 4
    threads_per_core : 2
    cpu_mhz : 2394
    hw_caps : bfebfbff:2c100800:00000000:00000740:029ee3ff:00000000:0 0000001:00000000
    virt_caps : hvm
    total_memory : 12278
    free_memory : 6500
    node_to_cpu : node0:0-7
    node_to_memory : node0:6500
    xen_major : 3
    xen_minor : 4
    xen_extra : .2
    xen_caps : xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x 86_32p hvm-3.0-x86_64
    xen_scheduler : credit
    xen_pagesize : 4096
    platform_params : virt_start=0xffff800000000000
    xen_changeset : unavailable
    cc_compiler : gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)
    cc_compile_by : root
    cc_compile_domain :
    cc_compile_date : Mon Mar 1 09:27:14 EST 2010
    xend_config_format : 4

    xm top
    xentop – 22:10:56 Xen 3.4.2
    3 domains: 1 running, 2 blocked, 0 paused, 0 crashed, 0 dying, 0 shutdown
    Mem: 12572772k total, 5916176k used, 6656596k free CPUs: 8 @ 2394MHz
    NAME STATE CPU(sec) CPU(%) MEM(k) MEM(%) MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS VBD_OO VBD_RD VBD_WR SSID
    Domain-0 —–r 576808 0.6 524288 4.2 no limit n/a 8 11 0 0 0 0 0 0 0
    msg –b— 545446 1.7 4194304 33.4 4194304 33.4 8 1 4750754 7539274 4 7456 56469 124600634 0
    udom –b— 244147 0.4 1048576 8.3 1048576 8.3 1 3 16262653 33888085 5 216 501407 234507947 0

  6. xm info 显示 cores_per_socket : 4 每个 CPU socket 上有物理4核,每核心2个线程 threads_per_core : 2,所以显示出来一共是逻辑8核 nr_cpus : 8.

  7. 明白。谢谢

  8. 这个需要关闭服务吗

发表评论