【问题标题】:Error trying to convert tables to InnoDB尝试将表转换为 InnoDB 时出错
【发布时间】:2014-12-14 23:04:04
【问题描述】:

我有一个 Percona 5.1 服务器在生产中使用我们生产数据库中的 MyISAM 表。为了支持数据库事务,我需要将表更新为 InnoDB。我们目前正在开发中使用 MySQL 5.5,迁移脚本可以通过简单的ALTER TABLE xyz ENGINE=InnoDB; 查询运行良好。但是在生产测试中(针对生产数据库的副本),我们遇到了一个错误:

mysql> ALTER TABLE `xyz` ENGINE=InnoDB;
ERROR 1005 (HY000): Can't create table 'InnoTest.#sql-644_dd133' (errno: 1478)

在我们的开发服务器上,使用与生产测试相同的数据库转储:

mysql> ALTER TABLE `xyz` ENGINE=InnoDB;
Query OK, 0 rows affected, 2 warnings (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 2

mysql> show warnings;
+---------+------+------------------------------------------------------------+
| Level   | Code | Message                                                    |
+---------+------+------------------------------------------------------------+
| Warning | 1478 | InnoDB: ROW_FORMAT=DYNAMIC requires innodb_file_per_table. |
| Warning | 1478 | InnoDB: assuming ROW_FORMAT=COMPACT.                       |
+---------+------+------------------------------------------------------------+

还有统计数据:

mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+-------------------------------------------+
| Variable_name           | Value                                     |
+-------------------------+-------------------------------------------+
| innodb_version          | 5.1.73-14.11                              |
| protocol_version        | 10                                        |
| version                 | 5.1.73-rel14.11-log                       |
| version_comment         | Percona Server (GPL), 14.11, Revision 603 |
| version_compile_machine | x86_64                                    |
| version_compile_os      | unknown-linux-gnu                         |
+-------------------------+-------------------------------------------+

mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+-------------------------+
| Variable_name           | Value                   |
+-------------------------+-------------------------+
| innodb_version          | 5.5.38                  |
| protocol_version        | 10                      |
| slave_type_conversions  |                         |
| version                 | 5.5.38-0ubuntu0.12.04.1 |
| version_comment         | (Ubuntu)                |
| version_compile_machine | x86_64                  |
| version_compile_os      | debian-linux-gnu        |
+-------------------------+-------------------------+

调试 gloomy.penguin:

mysql> ALTER TABLE `xyz` ENGINE=InnoDB;
ERROR 1005 (HY000): Can't create table 'InnoTest.#sql-644_df08c' (errno: 1478)
mysql> show errors;
+-------+------+------------------------------------------------------------+
| Level | Code | Message                                                    |
+-------+------+------------------------------------------------------------+
| Error | 1005 | Can't create table 'InnoTest.#sql-644_df08c' (errno: 1478) |
+-------+------+------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show create table visit;
| Table | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | xyz | CREATE TABLE `xyz` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `some_field` int(11) DEFAULT NULL,
  `some_field` tinyint(2) DEFAULT '0',
  `some_field` enum('a','b') DEFAULT 'b',
  `some_field` varchar(200) DEFAULT NULL,
  `some_field` date DEFAULT NULL,
  `some_field` time DEFAULT NULL,
  `some_field` datetime DEFAULT NULL,
  `some_field` text,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC |
1 row in set (0.02 sec)

mysql> SELECT @@GLOBAL.sql_mode;
+-------------------+
| @@GLOBAL.sql_mode |
+-------------------+
|                   |
+-------------------+
1 row in set (0.00 sec)

mysql> SELECT @@SESSION.sql_mode;
+--------------------+
| @@SESSION.sql_mode |
+--------------------+
|                    |
+--------------------+
1 row in set (0.00 sec)

mysql> ALTER TABLE `xyz` ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
ERROR 1005 (HY000): Can't create table 'InnoTest.#sql-644_df08c' (errno: 1478)
mysql> ALTER TABLE `xyz` ENGINE=InnoDB ROW_FORMAT=COMPACT;
Query OK, 0 rows affected (0.13 sec)
Records: 0  Duplicates: 0  Warnings: 0

开发服务器在 my.cnf 中没有任何 InnoDB 设置(默认 Ubuntu 12.04 mysql-server 安装),生产有这些:

innodb                         = FORCE
innodb_strict_mode             = 1
innodb_flush_method            = O_DIRECT
innodb_log_files_in_group      = 2
innodb_log_file_size           = 64M
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table          = 1
innodb_buffer_pool_size        = 592M

【问题讨论】:

标签: mysql innodb percona


【解决方案1】:

k...所以 OP 没有响应。这很酷。这是有关该错误的 mysql 文档...http://dev.mysql.com/doc/innodb-plugin/1.0/en/innodb-compression-syntax-warnings.html

  • 再次在 prod 中运行 ALTER TABLE xyz ENGINE=InnoDB;

  • 然后执行show errors;

  • 做一个show create table xyz;

  • 看看你是否处于 innodb 严格模式...(我会在 prod 和 non-prod 中这样做,看看有什么区别)SELECT @@GLOBAL.sql_mode; SELECT @@SESSION.sql_mode;

  • 来自文档:如果您在 InnoDB 严格模式下运行,KEY_BLOCK_SIZECOMPRESSED 以外的任何 ROW_FORMAT 的组合会生成错误,而不是警告,并且未创建表。

  • 使用你获得的信息和链接中的信息来确定你应该如何设置你的key_block_sizerow_format 让它接受它。

非 prod 数据库之所以有效,是因为:

  • KEY_BLOCK_SIZE 与任何其他ROW_FORMAT 一起指定会生成一条警告,您可以使用SHOW WARNINGS 查看该警告。但是,该表是未压缩的;指定的KEY_BLOCK_SIZE 被忽略)。 (在非 innodb-strict 模式下)

如果您需要更多帮助,请发布您获得的信息,我绝对可以提出建议...这可能是 alter table xyz engine=innodb ROW_FORMAT=COMPRESSED; 和/或使 innodb 模式设置等于您的非产品数据库设置。

key_block_size

more than you ever wanted to know on row formats

实际上,虽然...听起来 prod 处于 innodb 严格模式,而非 prod 不是。


found this:

innodb_strict_mode:

The innodb_strict_mode option controls whether InnoDB operates in strict mode, 
where conditions that are normally treated as warnings, cause errors instead 
(and the underlying statements fail).

This mode is the default setting in MySQL 5.5.5 and higher. 

您的一个版本高于 5.5.5,另一个低于。该默认值可能是差异......

【讨论】:

  • 我猜ROW_FORMAT=COMPACT 也可能是一个可行的选择。
  • 谢谢,我添加了更多信息。我从您要求的调试中看不到太多信息,但 COMPACT 可以工作。不知道为什么,会开始阅读。
  • select @@GLOBAL.sql_mode 为我工作...这里有一些关于检查它的更多信息:dev.mysql.com/doc/innodb-plugin/1.0/en/… 我真的认为 Prod 能够为你做行格式转换 b/c 它不在严格模式。但是 dev 是,所以它不能假设转换。
  • @DaveO - 你在 `my.cnf` 中对 innodb 的设置是什么?
  • 添加了上面的信息。看来这是由生产中设置的 innodb_strict_mode 引起的行格式问题。如上所述,它应该是开发中的默认值,因为它是 5.5.38,但我得到的只是警告。正如percona.com/blog/2014/01/14/… 所指出的,您会在 innodb_strict_mode 设置为 OFF 时收到这些警告。
猜你喜欢
  • 2020-09-10
  • 2016-04-05
  • 1970-01-01
  • 1970-01-01
  • 2018-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-24
相关资源
最近更新 更多