搜索
首页数据库mysql教程一次非法关机导致mysql数据表损坏的实例解决_MySQL

bitsCN.com

排查修复数据表的经过:

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数据库的数据表修复成功。

bitsCN.com
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
MySQL如何处理数据复制?MySQL如何处理数据复制?Apr 28, 2025 am 12:25 AM

MySQL通过异步、半同步和组复制三种模式处理数据复制。1)异步复制性能高但可能丢失数据。2)半同步复制提高数据安全性但增加延迟。3)组复制支持多主复制和故障转移,适用于高可用性需求。

您如何使用解释性语句分析查询性能?您如何使用解释性语句分析查询性能?Apr 28, 2025 am 12:24 AM

EXPLAIN语句可用于分析和提升SQL查询性能。1.执行EXPLAIN语句查看查询计划。2.分析输出结果,关注访问类型、索引使用情况和JOIN顺序。3.根据分析结果,创建或调整索引,优化JOIN操作,避免全表扫描,以提升查询效率。

您如何备份并还原MySQL数据库?您如何备份并还原MySQL数据库?Apr 28, 2025 am 12:23 AM

使用mysqldump进行逻辑备份和MySQLEnterpriseBackup进行热备份是备份MySQL数据库的有效方法。1.使用mysqldump备份数据库:mysqldump-uroot-pmydatabase>mydatabase_backup.sql。2.使用MySQLEnterpriseBackup进行热备份:mysqlbackup--user=root--password=password--backup-dir=/path/to/backupbackup。恢复时,使用相应的命

MySQL中慢速查询的常见原因是什么?MySQL中慢速查询的常见原因是什么?Apr 28, 2025 am 12:18 AM

MySQL慢查询的主要原因包括索引缺失或不当使用、查询复杂度、数据量过大和硬件资源不足。优化建议包括:1.创建合适的索引;2.优化查询语句;3.使用分表分区技术;4.适当升级硬件。

MySQL中有什么看法?MySQL中有什么看法?Apr 28, 2025 am 12:04 AM

MySQL视图是基于SQL查询结果的虚拟表,不存储数据。1)视图简化复杂查询,2)增强数据安全性,3)维护数据一致性。视图是数据库中的存储查询,可像表一样使用,但数据动态生成。

MySQL和其他SQL方言之间的语法有什么区别?MySQL和其他SQL方言之间的语法有什么区别?Apr 27, 2025 am 12:26 AM

mysqldiffersfromothersqldialectsinsyntaxforlimit,自动启动,弦乐范围,子征服和表面上分析。1)MySqluessLipslimit,whilesqlserverusestopopandoraclesrontersrontsrontsrontsronnum.2)

什么是mysql分区?什么是mysql分区?Apr 27, 2025 am 12:23 AM

MySQL分区能提升性能和简化维护。1)通过按特定标准(如日期范围)将大表分成小块,2)物理上将数据分成独立文件,3)查询时MySQL可专注于相关分区,4)查询优化器可跳过不相关分区,5)选择合适的分区策略并定期维护是关键。

您如何在MySQL中授予和撤销特权?您如何在MySQL中授予和撤销特权?Apr 27, 2025 am 12:21 AM

在MySQL中,如何授予和撤销权限?1.使用GRANT语句授予权限,如GRANTALLPRIVILEGESONdatabase_name.TO'username'@'host';2.使用REVOKE语句撤销权限,如REVOKEALLPRIVILEGESONdatabase_name.FROM'username'@'host',确保及时沟通权限变更。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器