MySQL数据库表修复 MyISAM_MySQL
一:MySQL中MyISAM表损坏原因总结:
1、 服务器突然断电导致数据文件损坏;强制关机,没有先关闭mysql 服务;mysqld 进程在写表时被杀掉。
2、 磁盘损坏。
3、 服务器死机。
4、 mysql 本身的bug 。
二:MySQL中MyISAM表损坏的症状总结:
1 、查询数据时报出错误:Incorrect key file for table: '...'. Try to repair it
2 、查询不能在表中找到行或返回不完全的数据。
3 、Error: Table '...' is marked as crashed and should be repaired 。
4 、打开表失败: Can't open file: ‘×××.MYI' (errno: 145) 。
三:MySQL中MyISAM表损坏的预防:
1 、定期检查MyISAM 表。可以使用myisamchk,也可以使用mysqlcheck,还可以使用check table。
2 、在做过大量的更新或删除操作后,使用mysqlcheck或者optimize table来优化表,这样既减少了文件碎片,又减少了表损坏的概率。 3 、关闭服务器前,先关闭mysqld (正常关闭服务,不要使用kill -9 来杀进程)。
4 、使用ups 电源,避免出现突然断电的情况。
5 、使用最新的稳定发布版mysql ,减少mysql 本身的bug 导致表损坏。
6 、对磁盘做raid ,减少磁盘出错并提高性能。
7 、数据库服务器最好只跑mysqld 和必要的其他服务,不要跑其他业务服务,这样减少死机导致表损坏的可能。
四:MySQL中MyISAM表损坏的修复总结:
1 、如果mysqld已经宕掉,且无法启动,那么可以通过mysiamchk工具来进行修复。此工具在mysqld服务没有启动时才可以使用。该工具可以检查并分析修复MyISAM表。
2 、如果mysqld仍在运行,或者可以重新启动,那么可以通过mysqlcheck工具来进行修复。或者直接通过mysql的内置修复SQL语句来修复:CHECK TABLE,REPAIR TABLE ,ANALYSE TABLE,OPTIMIZE TABLE。这两种方法可以同样达到对表的修复作用。 以上两种方式各有应用场景。
MySQL数据表损坏的巧妙修复 修复mysql表之前首先要知道是哪个表出了问题
可以用root登录后在information_schema里查找有问题的表名
select TABLE_SCHEMA as DB_DBNAME,TABLE_NAME from INFORMATION_SCHEMA.tables where engine is null;
可以通过事件查看器里是否有
应用程序日志--类型为"错误"--事件来源为"Mysql"的错误日志,大概内容为
1 xxxxx: Table '.xxxx' is marked as crashed and should be repaired
或者直接在phpmyadmin中查看有哪些表出了问题比如显示“使用中”
如果查到问题表后,可以使用一下命令来修复mysql数据库中的MYISAM表
1、check, repair
例如abc的test表有问题
复制代码 代码如下:
# mysql -u root -p 'abc'; //登录mysql控制台,并进入abc数据库
mysql> check table test; //如果有问题Msg_type里会有warning或error。没有问题的话出现的结果Status是OK
mysql> repair table test; // 修复test表(多个表名用“逗号”隔开)
mysql> check table test; // 再次检查确认是否修复成功
2. myisamchk, isamchk
其中myisamchk适用于MYISAM类型的数据表,而isamchk适用于ISAM类型的MySQL数据表。这两条命令的主要参数相同,一般新的系统都使用MYISAM作为缺省的数据表类型,这里以myisamchk为例子进行说明。当发现某个数据表出现问题时可以使用:
myisamchk tablename.MYI
进行检测,如果需要修复的话,可以使用:
myisamchk -of tablename.MYI
关于myisamchk的详细参数说明,可以参见它的使用帮助。需要注意的时在进行修改时必须确保MySQL服务器没有访问这个MySQL数据表,保险的情况下是最好在进行检测时把MySQL服务器Shutdown掉。
mysqladmin -uroot -p shutdown
另外可以把下面的命令放在你的rc.local里面启动MySQL服务器前:
[ -x /tmp/MySQL.sock ] && /pathtochk/myisamchk -of /DATA_DIR/*/*.MYI
其中的/tmp/MySQL.sock是MySQL监听的Sock文件位置,对于使用RPM安装的用户应该是/var/lib/MySQL/MySQL.sock,对于使用源码安装则是/tmp/MySQL.sock可以根据自己的实际情况进行变更,而pathtochk则是myisamchk所在的位置,DATA_DIR是你的MySQL数据库存放的位置。
需要注意的时,如果你打算把这条命令放在你的rc.local里面,必须确认在执行这条指令时MySQL服务器必须没有启动!
3、检测修复所有数据库(表)
复制代码 代码如下:
MySQLcheck -A -o -r -p
mysqlcheck --all-databases -r

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.
