gpt4 book ai didi

mysql - 从 ibdata1 恢复 mysql 数据库

转载 作者:可可西里 更新时间:2023-11-01 07:02:46 28 4
gpt4 key购买 nike

我有一个客户似乎已经从他们的本地机器上丢失了所有的 mysql 数据库。他们在我不太熟悉的 Mac 上,我在 Ubuntu 上。数据库文件夹中没有 .MYD 或 .MYI 文件,只有 .frm 文件。我让他们压缩了 mysql 和 sight 文件夹(sight 是我们需要的数据库),以及 ibdata1、ib_logfile0 和 ib_logfile1 文件。我为 mysql 创建了第二个文件夹/var/lib/mysql2,并将文件和文件夹移动到那里。我将新文件夹和文件添加到 mysql:mysql,编辑/etc/mysql/my.cnf 以指向新文件夹,编辑/etc/apparmor.d/usr.sbin.mysqld,然后重新启动 apparmor 和 mysql。但是,我在 mysql 错误日志中收到以下错误:

130308 17:38:16 [Note] Plugin 'FEDERATED' is disabled.
130308 17:38:16 InnoDB: Initializing buffer pool, size = 8.0M
130308 17:38:16 InnoDB: Completed initialization of buffer pool
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
130308 17:38:16 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
130308 17:38:16 InnoDB: Error: space id and page n:o stored in the page
InnoDB: read in are 0:589824, should be 0:7!
130308 17:38:16 InnoDB: Error: page 589824 log sequence number 786432 0
InnoDB: is in the future! Current system log sequence number 0 63932940.
InnoDB: Your database may be corrupt or you may have copied the InnoDB
InnoDB: tablespace but not the InnoDB log files. See
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/forcing-innodb-recovery.html
InnoDB: for more information.
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 7.
InnoDB: You may have to recover from a backup.
130308 17:38:16 InnoDB: Page dump in ascii and hex (16384 bytes):
len 16384; hex 0008000000090000000a0000000b0000000c00000000000000000000000202720000 (snipped because this goes on for a while)
Tg 9 <o q E i F / D ;InnoDB: End of page dump
130308 17:38:16 InnoDB: Page checksum 4146777650, prior-to-4.0.14-form checksum 1800374066
InnoDB: stored checksum 524288, prior-to-4.0.14-form stored checksum 0
InnoDB: Page lsn 786432 0, low 4 bytes of lsn at page end 0
InnoDB: Page number (if stored to page already) 589824,
InnoDB: space id (if created with >= MySQL-4.1.1 and stored already) 0
InnoDB: Page may be a freshly allocated page
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 7.
InnoDB: You may have to recover from a backup.
InnoDB: It is also possible that your operating
InnoDB: system has corrupted its own file cache
InnoDB: and rebooting your computer removes the
InnoDB: error.
InnoDB: If the corrupt page is an index page
InnoDB: you can also try to fix the corruption
InnoDB: by dumping, dropping, and reimporting
InnoDB: the corrupt table. You can use CHECK
InnoDB: TABLE to scan your table for corruption.
InnoDB: See also http://dev.mysql.com/doc/refman/5.1/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
InnoDB: Ending processing because of a corrupt database page.

我尝试将 innodb_force_recovery = 4 添加到 my.cnf 文件中,这会生成一大堆不同的错误:

130308 17:48:30 [Note] Plugin 'FEDERATED' is disabled.
130308 17:48:30 InnoDB: Initializing buffer pool, size = 8.0M
130308 17:48:30 InnoDB: Completed initialization of buffer pool
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
130308 17:48:30 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
130308 17:48:30 InnoDB: Error: space id and page n:o stored in the page
InnoDB: read in are 0:589824, should be 0:7!
130308 17:48:30 InnoDB: Error: page 589824 log sequence number 786432 0
InnoDB: is in the future! Current system log sequence number 0 63932940.
InnoDB: Your database may be corrupt or you may have copied the InnoDB
InnoDB: tablespace but not the InnoDB log files. See
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/forcing-innodb-recovery.html
InnoDB: for more information.
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 7.
InnoDB: You may have to recover from a backup.

还有一大堆,如果有帮助我可以提供。非常感谢任何关于从这里尝试什么的建议,谢谢。


编辑:我尝试按照此处的步骤操作,但在使用他使用的命令行序列运行 mysql 时遇到问题:

http://blog.shiraj.com/2012/10/extract-data-from-mysql-ibdata1-data-file/

最佳答案

以下对我有用:

  • 在你的 my.cnf 中设置 innodb_force_recovery = 1

  • 尝试让您的 mysqld 重新启动。如果不是,重复步骤 #1 并递增innodb_force_recovery by each 直到成功。使用指南帮助您了解每次递增时发生的情况:http://dev.mysql.com/doc/refman/5.0/en/forcing-innodb-recovery.html

  • 一旦 mysqld 运行,尝试转储所有数据库

mysqldump -u root -p --all-databases > /tmp/mysqldump-all.sql
  • 如果不成功,您必须先在数据库级别尝试
mysqldump -u root -p --databases db_name > mysqldump-db_name.sql
  • 如果不成功,您将不得不在桌面上尝试

SELECT * FROM table_name INTO OUTFILE '/tmp/table_name.sql'

  • 一旦其中一个成功并且所有数据库或所有表都已导出,停止 mysqld

  • 移动您的 ib_logfile* > ib_logfile*.bak。这些通常位于您的 mysql 数据目录中。

  • 如果在第一步中您增加了 innodb_force_recovery => 4,则需要将其设置为低于 4。从 5.6.15 开始,innodb_force_recovery 设置为 4 或更大会使 InnoDB 处于只读模式。

  • 启动mysqld服务器

  • 导入导出的数据库或表

mysql -u root -p < /tmp/mysqldump-all.sql

  • 增加您的 innodb_force_recovery => 1

  • 重启mysqld服务器

关于mysql - 从 ibdata1 恢复 mysql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15304708/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com