数据库

本类阅读TOP10

·SQL语句导入导出大全
·SQL Server日期计算
·SQL语句导入导出大全
·SQL to Excel 的应用
·Oracle中password file的作用及说明
·MS SQLServer OLEDB分布式事务无法启动的一般解决方案
·sqlserver2000数据库置疑的解决方法
·一个比较实用的大数据量分页存储过程
·如何在正运行 SQL Server 7.0 的服务器之间传输登录和密码
·SQL中两台服务器间使用连接服务器

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
InnoDB 中文参考手册 --- 15 故障检测与修复

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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`。那么你就可以转储或移除重命名后的表了。 表名中的反引号是必须的,因为临时表命名中包含字符 '-'

 




相关文章

相关软件