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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

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.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.
