Home Database Mysql Tutorial MySQL数据库中某些数据损坏的修护

MySQL数据库中某些数据损坏的修护

Jun 07, 2016 pm 04:13 PM
mysql main data database article

以下的文章主要讲述的是MySQL数据库中某些数据损坏的实际恢复过程,前几天因为MySQL数据库中的数据损坏,我就尝试了一下恢复数据的实际操作,之后整理以下文档,供各位参考,以备各位同事以后如有类似问题。 环境:Windows2003 数据库:MySQL(和PHP搭配之最

以下的文章主要讲述的是MySQL数据库中某些数据损坏的实际恢复过程,前几天因为MySQL数据库中的数据损坏,我就尝试了一下恢复数据的实际操作,之后整理以下文档,供各位参考,以备各位同事以后如有类似问题。

环境:Windows2003

数据库:MySQL(和PHP搭配之最佳组合)

损坏数据文件名:function_products

将MySQL数据库内容物理文件直接导入到MySQL(和PHP搭配之最佳组合)\data下,每只表各3个文件,依次分别为:

.frm .myd .myi。首先我第一想到的是去网上搜索,寻找类似的工具,试图通过工具来恢复已损坏的文件,于是我在google上查找,找到一款名为MySQL(和PHP搭配之最佳组合)recovery的工具,安装后我用其进行恢复,只可惜效果太不理想,几十MB大的数据文件,恢复之后它提示我竟然只有几十KB。

我又想到了MySQL(和PHP搭配之最佳组合)下应有自己本身的修复程序等,于是想通过其来进行恢复,心想应不会太差劲吧,在网上查找了资料,提示:由于临时断电,使用kill -9中止MySQL(和PHP搭配之最佳组合)服务进程,或者是MySQL(和PHP搭配之最佳组合)正在高速运转时进行强制备份操作时等,所有的这些都可能会毁坏MySQL(和PHP搭配之最佳组合)的数据文件。如果在被干扰时,服务正在改变文件,文件可能会留下错误的或不一致的状态。因为这样的毁坏有时是不容易被发现的,当你发现这个错误时可能是很久以后的事了。

于是,当你发现这个问题时,也许所有的备份都有同样的错误。我想我现在碰到的问题可能是这个问题,因为备份的数据也是有部分损坏的数据,所以导致不能完全运行, 意识到myisamchk程序对用来检查和修改的MySQL(和PHP搭配之最佳组合)数据文件的访问应该是唯一的。

如果MySQL(和PHP搭配之最佳组合)服务正在使用某一文件,并对myisamchk正在检查的文件进行修改,myisamchk会误以为发生了错误,并会试图进行修复--这将导致MySQL(和PHP搭配之最佳组合)服务的崩溃!这样,要避免这种情况的发生,通常我们需要在工作时关闭MySQL(和PHP搭配之最佳组合)服务。

作为选择,你也可以暂时关闭服务以制作一个文件的拷贝,然后在这个拷贝上工作。当你做完了以后,重新关闭服务并使用新的文件取代原来的文件(也许你还需要使用期间的变更日志)。

MySQL(和PHP搭配之最佳组合)数据目录不是太难理解的。每一个MySQL数据库对应一个子目录,每个子目录中包含了对应于这个数据库中的数据表的文件。每一个数据表对应三个文件,它们和表名相同,但是具有不同的扩展名。

tblname.frm文件是表的定义,它保存了表中包含的数据列的内容和类型。tblname.myd文件包含了表中的数据。tblname.myi文件包含了表的索引(例如,它可能包含lookup表以帮助提高对表的主键列的查询)。 要检查一个表的错误,只需要运行myisamchk(在MySQL(和PHP搭配之最佳组合)的bin目录下)并提供文件的位置和表名,或者是表的索引文件名:

<ol class="dp-xml">
<li class="alt"><span><span>% myisamchk /usr/local/MySQL(和PHP搭配之最佳组合)/var/dbname/tblname   </span></span></li>
<li><span>% myisamchk /usr/local/MySQL(和PHP搭配之最佳组合)/var/dbname/tblname.myi   </span></li>
</ol>
Copy after login

上面的两个命令都可以执行对指定表的检查。要检查MySQL数据库中所有的表,可以使用通配符:

<ol class="dp-xml"><li class="alt"><span><span>% myisamchk /usr/local/MySQL(和PHP搭配之最佳组合)/var/dbname/*.myi  </span></span></li></ol>
Copy after login

要检查所有MySQL数据库中的所有表,可以使用两个通配符:

<ol class="dp-xml"><li class="alt"><span><span>% myisamchk /usr/local/MySQL(和PHP搭配之最佳组合)/var/*/*.myi  </span></span></li></ol>
Copy after login

如果不带任何选项,myisamchk将对表文件执行普通的检查。如果你对一个表有怀疑,但是普通的检查不能发现任何错误,你可以执行更彻底的检查(但是也更慢!),这需要使用--extend-check选项:

<ol class="dp-xml"><li class="alt"><span><span>% myisamchk --extend-check /path/to/tblname  </span></span></li></ol>
Copy after login

对错误的检查是没有破坏性的,这意味着你不必担心执行对你的数据文件的检查会使已经存在的问题变得更糟。另一方面,修复选项,虽然通常也是安全的,但是它对你的数据文件的更改是无法撤消的。

因为这个原因,我们强烈推荐你试图修复一个被破坏的表文件时首先做个备份,并确保在制作这个备份之前你的MySQL(和PHP搭配之最佳组合)服务是关闭的。
我在Win2003下通过命令提示符,以上的相关内容就是对MySQL数据库中部分数据损坏恢复过程的介绍,望你能有所收获。


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

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: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

Query optimization in MySQL is essential for improving database performance, especially when dealing with large data sets Query optimization in MySQL is essential for improving database performance, especially when dealing with large data sets Apr 08, 2025 pm 07:12 PM

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

Can I retrieve the database password in Navicat? Can I retrieve the database password in Navicat? Apr 08, 2025 pm 09:51 PM

Navicat itself does not store the database password, and can only retrieve the encrypted password. Solution: 1. Check the password manager; 2. Check Navicat's "Remember Password" function; 3. Reset the database password; 4. Contact the database administrator.

How to create navicat premium How to create navicat premium Apr 09, 2025 am 07:09 AM

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

How to view mysql How to view mysql Apr 08, 2025 pm 07:21 PM

View the MySQL database with the following command: Connect to the server: mysql -u Username -p Password Run SHOW DATABASES; Command to get all existing databases Select database: USE database name; View table: SHOW TABLES; View table structure: DESCRIBE table name; View data: SELECT * FROM table name;

How to copy tables in mysql How to copy tables in mysql Apr 08, 2025 pm 07:24 PM

Copying a table in MySQL requires creating new tables, inserting data, setting foreign keys, copying indexes, triggers, stored procedures, and functions. The specific steps include: creating a new table with the same structure. Insert data from the original table into a new table. Set the same foreign key constraint (if the original table has one). Create the same index. Create the same trigger (if the original table has one). Create the same stored procedure or function (if the original table is used).

How to view database password in Navicat for MariaDB? How to view database password in Navicat for MariaDB? Apr 08, 2025 pm 09:18 PM

Navicat for MariaDB cannot view the database password directly because the password is stored in encrypted form. To ensure the database security, there are three ways to reset your password: reset your password through Navicat and set a complex password. View the configuration file (not recommended, high risk). Use system command line tools (not recommended, you need to be proficient in command line tools).

See all articles