一个MySQL数据库非法关机造成数据表损坏的实例

数据库 MySQL
本文主要介绍了修复由于非法硬件关机造成MySQL数据库数据表损坏的过程,希望能够对您有所帮助。

本文我们介绍由于非法硬件关机,造成了MySQL数据库数据表损坏,数据库不能正常运行的一个实例,接下来是作者排查错误的过程,让我们来一起了解一下吧。

排查修复数据表的经过如下:

 

1、访问网页,提示错误,连接不到数据库。

2、启动mysql服务,卸载和关闭rpm安装的mysql服务(昨天安装postfix好像yum安装了mysql),用netstat -anp |grep mysqld 命令查看mysql服务没有起来,用mysql -uroot -p也连接不到服务器。

3、查看错误提示:

 

  1. 110726 17:02:23 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.  
  2.  
  3. 110726 17:02:23 [ERROR] /usr/local/mysql/libexec/mysqld: Table './mysql/host' is marked as crashed and last (automatic?) repair failed  
  4.  
  5. 110726 17:02:23 [ERROR] Fatal error: Can't open and lock privilege tables: Table './mysql/host' is marked as crashed and last (automatic?) repair failed  
  6.  
  7. 110726 17:02:23 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended  
  8.  
  9. 110726 17:24:31 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql  
  10.  
  11. 110726 17:24:31 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead. 

 

发现提示数据库表损坏。(./mysql/host)

4、修复数据库表:

 

  1. cd /var/lib/mysql/mysql  
  2.  
  3. myisamchk -of host.MYI  
  4.  
  5. - recovering (with keycache) MyISAM-table 'host.MYI'  
  6.  
  7. Data records: 0  
  8.  
  9. 表host.MYI修复成功。 

 

5、再次启动服务,查看服务是否启动,登录mysql,还是不行。所以再次查看错误日志。

 

  1. /usr/local/mysql/libexec/mysqld: Table './mysql/plugin' is marked as crashed and last (automatic?) repair failed  
  2.  
  3. /usr/local/mysql/libexec/mysqld: Table 'plugin' is marked as crashed and last (automatic?) repair failed  
  4.  
  5. 110726 17:24:31 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.  
  6.  
  7. 110726 17:24:31 [ERROR] /usr/local/mysql/libexec/mysqld: Table './mysql/user' is marked as crashed and last (automatic?) repair failed  
  8.  
  9. 110726 17:24:31 [ERROR] Fatal error: Can't open and lock privilege tables: Table './mysql/user' is marked as crashed and last (automatic?) repair failed  
  10.  
  11. 110726 17:24:31 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended  
  12.  
  13. 110726 17:27:13 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql  
  14.  
  15. 110726 17:27:13 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead. 

 

6、又发现./mysql/user表损坏。

 

  1. [root@localhost mysql]# myisamchk -of user.MYI  
  2.  
  3. - recovering (with keycache) MyISAM-table 'user.MYI'  
  4.  
  5. Data records: 6 

 

7、表修复成功,但是还是启动不了服务,继续看错误日志。

 

  1. /usr/local/mysql/libexec/mysqld: Table './mysql/plugin' is marked as crashed and last (automatic?) repair failed  
  2.  
  3. /usr/local/mysql/libexec/mysqld: Table 'plugin' is marked as crashed and last (automatic?) repair failed  
  4.  
  5. 110726 17:27:13 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.  
  6.  
  7. 110726 17:27:13 [ERROR] /usr/local/mysql/libexec/mysqld: Table './mysql/db' is marked as crashed and last (automatic?) repair failed  
  8.  
  9. 110726 17:27:13 [ERROR] Fatal error: Can't open and lock privilege tables: Table './mysql/db' is marked as crashed and last (automatic?) repair failed  
  10.  
  11. 110726 17:27:13 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended 

 

8、最后一个错误,是./mysql/db表还没有修复好继续修复./mysql/db表。

9、执行下面的命令修复./mysql/db表:

  1. [root@localhost mysql]# myisamchk -of db.MYI  
  2.  
  3. - recovering (with keycache) MyISAM-table 'db.MYI'  
  4.  
  5. Data records: 0  
  6.  
  7. Data records: 2 

 

10、最后启动mysql服务。

 

  1. /usr/local/mysql/bin/mysqld_safe & 

 

11、查看服务是否在运行。

 

  1. [root@localhost ~]# netstat -anp | grep mysqld  
  2.  
  3. tcp        0      0   
  4.  
  5. 0.0.0.0:3306                  
  6.  
  7. 0.0.0.0:*                   LISTEN        
  8.  
  9. 4360/mysqld           
  10.  
  11. unix  2      [ ACC ]     STREAM     LISTENING     14172    
  12.  
  13. 4360/mysqld         /tmp/mysql.sock 

 

这时发现服务已运行。

12、登录mysql试试。

 

  1. [root@localhost ~]# mysql -uroot -p123456  
  2.  
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  4.  
  5. Your MySQL connection id is 35  
  6.  
  7. Server version: 5.1.55-log Source distribution  
  8.  
  9. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.  
  10.  
  11. This software comes with ABSOLUTELY NO WARRANTY. This is free software,  
  12.  
  13. and you are welcome to modify and redistribute it under the GPL v2 license  
  14.  
  15. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  16.  
  17. mysql>  

 

能登录。

13、在打开网页,已经能正常访问。证明MySQL数据库的数据表就修复成功了。

关于MySQL数据库数据表损坏的问题就介绍到这里了,如果您有兴趣了解更多关于MySQL数据库的知识,可以看一下这里的文章:http://database.51cto.com/mysql/,相信一定会带给您收获的!

【编辑推荐】

  1. 用mysqldumpslow分析执行较慢的SQL语句
  2. 关于MySQL事务的操作示例以及注意事项
  3. 使用MySQL Proxy告终读写离别的操作实例
  4. 开启了log-bin的MySQL数据库如何备份还原
  5. MySQL数据库安装过程中常见错误的解决方案
责任编辑:赵鹏 来源: 网易博客
相关推荐

2010-06-09 16:55:47

MySQL数据表

2010-05-12 18:35:25

MySQL数据表

2011-07-20 17:02:51

Oracle数据库

2017-05-25 10:23:13

数据a表b表

2010-06-13 17:35:17

MySQL数据表

2011-07-20 13:40:00

SQLite数据库查询数据

2010-05-17 17:54:39

MySQL 数据库

2011-07-20 12:55:17

SQLite数据库插入数据

2010-05-20 14:25:25

2018-02-25 17:30:18

2011-07-20 13:18:01

SQLite数据库修改和删除数据

2011-08-18 18:18:05

MySQL数据库优化

2022-12-28 08:17:36

数据库数据导出

2011-07-21 16:28:20

MySQL数据库带游标的存储过程

2011-08-22 16:41:35

MySQL1067进程意外终止

2011-07-20 14:57:47

SQLite数据库ORDER BYGROUP BY

2021-03-04 14:10:04

Mysql数据库数据表

2011-08-02 12:46:46

Oracle数据表建立索引

2010-10-13 11:54:00

MySQL数据库表

2009-06-22 13:50:00

java连接mysql
点赞
收藏

51CTO技术栈公众号