文摘首页 >> 网页制作·视觉设计·3D STUDIO·FLASH制作·网络攻防·病毒播报·编程开发·系统维护·网站经营·视频剪辑·文摘论坛
 







线




访




 
 ■ 您现在的位置: 福建大学生在线 >> 文摘 >> 编程开发 >> 数据库技术 >> My Sql >> 文摘正文
 
InnoDB 中文参考手册 --- 15 故障检测与修复
作者:佚名 文章来源:不详 点击数: 更新时间:2007-3-27 1:53:00
InnoDB 中文参考手册 --- 犬犬(心帆)翻译

15 故障检测与修复

  • 一个普遍的规则就是当一个操作挫败或你怀疑是一个 bug,你必须查看 MySQL 服务程序 mysqld 的错误日志(error log),通常命名为 ''''hostname''''.err,或 Windows 下的 mysql.err
  • 当进行故障检测并修复时,在命令提示符下运行 MySQL 服务程序 mysqld 是一个较好的方式,不要通过 safe_mysqld 的包装(wrapper)或以 Windows 服务启动。你可以看到 mysqld 在命令提示符窗口上的显示,而可以更好地把握什么将要发生。在 Windows 下,你必须以 --console 选项运行 mysqld-max 来使输出直接显示在 MS-DOS 提示符窗口上。
  • 如果问题与性能有关(performance-related),或你的服务看起来将要挂起,你可以使用 innodb_monitor 来显示 InnoDB 内部状态的相关信息。如果问题是由于锁定引起,使用 innodb_lock_monitor。如果问题是在建表时或其它的数据字典操作,使用 innodb_table_monitor 显示 InnoDB 内部数据字典的内容。
  • 如果你怀疑表已损坏,在表上运行 CHECK TABLE

15.1 发现并修复数据字典错误的操作

一个特殊的有关表的问题就是 MySQL 在它自己的数据目录下的 .frm 文件中保存它自己的数据字典信息,然而 InnoDB 将它自己的信息保存在数据文件中 InnoDB 自己的数据字典中。如果你在外部移走了 .frm 文件,或在 MySQL < 3.23.44 的版本中使用了 DROP DATABASE ,或在数据字典操作时服务器崩溃了,那么 .frm 文件可能会因与 InnoDB 内部的数据字典 out-of-sync 而结束。

与数据字典 out-of-sync 的一个故障现象就是 CREATE TABLE 语句的调用失败。那么你必须查看错误日志。如果错误述说为表在 InnoDB 内部数据字典中已存在,那么一定在 InnoDB 的数据文件中存在一个孤表(orphaned table),没有相对应的 .frm 文件。

InnoDB: Error: table test/parent already exists in InnoDB internal

 InnoDB: data dictionary. Have you deleted the .frm file

 InnoDB: and not used DROP TABLE? Have you used DROP DATABASE

 InnoDB: for InnoDB tables in MySQL version <= 3.23.43?

 InnoDB: See the Restrictions section of the InnoDB manual.

 InnoDB: You can drop the orphaned table inside InnoDB by

 InnoDB: creating an InnoDB table with the same name in another

 InnoDB: database and moving the .frm file to the current database.

 InnoDB: Then MySQL thinks the table exists, and DROP TABLE will

 InnoDB: succeed.

 
你可以跟从上面错误日志中的提示移除(drop)孤表(orphaned table)。

 

另一个与数据字典 out-of-sync 的故障现象就是 MySQL 提示不能打开一个文件 yourtablename.InnoDB 的错误。

ERROR 1016: Can''''t open file: ''''child2.InnoDB''''. (errno: 1)

 
在错误日志中可以发现:
InnoDB: Cannot find table test/child2 from the internal data dictionary

 InnoDB: of InnoDB though the .frm file for the table exists. Maybe you

 InnoDB: have deleted and recreated InnoDB data files but have forgotten

 InnoDB: to delete the corresponding .frm files of InnoDB tables?

 
意思就是有一个孤的(orphaned) .frm 文件,在 InnoDB 中没有相应的表与之对应。可以通过手工删除 .frm 文件来移除它。

 

如果在一个 ALTER TABLE 操作时 MySQL 崩溃了,你可能会因在 InnoDB 表空间在存在一个孤的临时表而告终。通过 innodb_table_monitor ,你可以发现一个名为 #sql... 的表,但是 MySQL 不允许访问任何一个如此命名的表,你将不能转储(dump)或移除(drop)它。解决办法就是使用从 3.23.48 开始 InnoDB 支持的一个特殊的机制。

如果在表空间内存在一个孤表(orphaned table) #sql... ,那么调用

CREATE TABLE `rsql..._recover_innodb_tmp_table`(...) type = innodb;

 

使表定义与临时表相似,你可以使 InnoDB 将孤表重命名为 `rsql..._recover_innodb_tmp_table`。那么你就可以转储或移除重命名后的表了。 表名中的反引号是必须的,因为临时表命名中包含字符 ''''-''''

 

文摘录入:一叶知秋    责任编辑:一叶知秋 
【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
  • 上一篇文摘:

  • 下一篇文摘:
  • 版权所有:福建大学生在线(www.fjstu.net)All Right Reserved 2003-2006
    福建大学生在线站务组 - 有你的加入更精彩 - 站务成员全年招募中
    网站备案号:闽ICP备05000367号 广告投放QQ:383870619 欢迎商家加盟