如何解决一次非法关机导致mysql数据表损坏的问题
- 更新时间:2020-04-23 08:31:58
- 编辑:戈文德
排查修复数据表的经过:
1、访问网页,提示错误,连接不到数据库。
2、启动mysql服务,卸载和关闭rpm安装的mysql服务
(昨天安装postfix好像yum安装了mysql),用netstat -anp |grep mysqld 命令查看mysql服务没有起来,用mysql -uroot -p也连接不到服务器。
3、查看错误提示:
110726 17:02:23 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
110726 17:02:23 [ERROR] /usr/local/mysql/libexec/mysqld: Table './mysql/host' is marked as crashed and last (automatic?) repair failed
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 110726 17:02:23 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended
110726 17:24:31 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
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、修复数据库表:
cd /var/lib/mysql/mysql
myisamchk -of host.MYI
- recovering (with keycache) MyISAM-table 'host.MYI'
Data records: 0
表host.MYI修复成功。
5、再次启动服务,查看服务是否启动,登录mysql,还是不行。所以再次查看错误日志。
/usr/local/mysql/libexec/mysqld: Table './mysql/plugin' is marked as crashed and last (automatic?) repair failed
/usr/local/mysql/libexec/mysqld: Table 'plugin' is marked as crashed and last (automatic?) repair failed
110726 17:24:31 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
110726 17:24:31 [ERROR] /usr/local/mysql/libexec/mysqld: Table './mysql/user' is marked as crashed and last (automatic?) repair failed
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 110726 17:24:31 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended
110726 17:27:13 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
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表损坏。
[root@localhost mysql]# myisamchk -of user.MYI
- recovering (with keycache) MyISAM-table 'user.MYI'
Data records: 6
7、表修复成功,但是还是启动不了服务,继续看错误日志。
/usr/local/mysql/libexec/mysqld: Table './mysql/plugin' is marked as crashed and last (automatic?) repair failed
/usr/local/mysql/libexec/mysqld: Table 'plugin' is marked as crashed and last (automatic?) repair failed
110726 17:27:13 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
110726 17:27:13 [ERROR] /usr/local/mysql/libexec/mysqld: Table './mysql/db' is marked as crashed and last (automatic?) repair failed
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
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表:
[root@localhost mysql]# myisamchk -of db.MYI
- recovering (with keycache) MyISAM-table 'db.MYI'
Data records: 0
Data records: 2
10、最后启动mysql服务。
/usr/local/mysql/bin/mysqld_safe &
11、查看服务是否在运行。
[root@localhost ~]# netstat -anp | grep mysqld
tcp0 0
0.0.0.0:3306
0.0.0.0:* LISTEN
4360/mysqld
unix 2 [ ACC ] STREAM LISTENING 14172
4360/mysqld /tmp/mysql.sock
这时发现服务已运行。
12、登录mysql试试。
[root@localhost ~]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.1.55-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
可以登录。
13、打开网页,已经可以正常访问了,说明MySQL数据库的数据表修复成功。
相关教程
-
MySQL数据库查看数据表占用空间大小和记录数的实例讲解
这篇文章主要介绍了MySQL数据库查看数据表占用空间大小和记录数的方法,如果想知道MySQL数据库中每个表占用的空间、表记录的行数的话,可以打开MySQL的information_schema 数据库查询,本文就讲解查
发布时间:2019-07-25
-
深入理解MySql数据表之间的连接、查询
这篇文章主要介绍了MySql数据表之间的连接、查询,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
发布时间:2020-03-06
-
PHP与MySQL高性能应用开发
PHP与MySQL高性能应用开发书中不仅讲解了OOP、设计模式,也讲解了如何进行性能优化和调试。甚至,还对于语言之外的代码重构进行了讲解,本书面向的对象是有一定PHP基础,但是又想深入学习的PHP开发者,欢迎免费下载
大小:60.5 MBPHP开发电子书
-
MySQL从入门到项目实践
MySQL从入门到项目实践 (超值版)采用基本知识关键运用关键技术高級运用应用领域新项目实践活动构造和循序渐进,由深到精的学习方式开展解读。本书分成6篇29章。最先解读MySQL的安裝与配备
大小:314.8 MBMySQL电子书
-
MySQL DBA修炼之道
MySQL DBA修炼之道 以实战讲解为主,摒弃了生产实践中不常用的知识和技术。书中内容主要分为5部分。第壹部分介绍MySQL的应用领域和适用场景、基础架构、常见生产环境部署方式,以及MySQL安
大小:4.9 MBMySQL电子书
-
MySQL 8 Cookbook
MySQL 8的更新幅度在MySQL历史上可谓空前,增添很多重磅新特性——“数据字典”取消了已存在几十年的frm文件,将插件式数据库的重心偏向InnoDB,极大提高meta data的访问性能,并支持了DDL原子性
大小:206.5 MBMySQL电子书
-
MySQL技术内幕:InnoDB存储引擎
《MySQL技术内幕:InnoDB存储引擎(第2版)》 由国内资深MySQL专家亲自执笔,国内外多位数据库专家联袂推荐。作为国内唯一一本关于InnoDB的专著,《MySQL技术内幕:InnoDB存储引擎(第2版)》的第1版广受
大小:39.3 MBMySQL电子书
-
MySQL技术精粹:架构、高级特性、性能优化与集群实战
这书对于MySQL高级客户,详尽解读MySQL高級应用技术性。书中详细说明了每一个知识结构图及其数据库实际操作的方式和方法。这书重视实战实际操作,协助读者由浅入深地把握MySQL中的各类高
大小:271.3 MBMySQL电子书
-
MySQL入门经典
《 MySQL入门经典 》以新手为关键,全方位解读MySQL数据库系统。在內容分配上由浅人深,让用户由浅入深地把握编程技术;在內容解读上融合丰富多彩的详解和品牌形象的形容,协助用户了解
大小:313.3 MBMySQL入门电子书
-
MySQL王者晋级之路
本书深入剖析MySQL数据库体系结构,实战演练备份恢复、主从复制,详解高可用集群架构的设计与实践过程,详细梳理优化思路,展现新版本的特性,并与真实生产案例相结合,通过核心原理到“王者”实战,全面覆盖MySQL数据库的知识点
大小:76.5 MBMySQL数据库电子书
-
MySQL运维内参
《MySQL运维内参:MySQL、Galera、Inception核心原理与最佳实践》是一本介绍MySQL数据库知识的专业书籍,从核心原理到最佳实践,深入浅出、抽丝剥茧地进行讲解,不仅从源码和运维两个角度介绍
大小:162 MBMySQL电子书
-
MySQL必知必会
大小:5.7 MBMySQL电子书