MySQL 5.5 innodb_large_prefix 配置设置未生效

标签 mysql innodb

我在 Debian Linux 上运行 MySQL 5.5.55,我想启用 innodb_large_prefix 设置,这样我就可以拥有大于 767 字节的表索引。

我的/etc/mysql/my.cnf 文件中有以下配置:

[mysqld]
...
innodb_file_per_table=1
innodb-large-prefix=ON
innodb_file_format=barracuda

(我也尝试过 innodb_large_prefix=ON。)

更新:我仔细检查过,没有其他配置文件存在,例如/etc/my.cnf, /usr/etc/my.cnf, ~root/.my.cnf, ~mysql/.my.cnf)

但是当我重新启动 MySQL 时,事件配置显示为:

| innodb_file_format             | Barracuda              |
| innodb_large_prefix            | OFF                    |
| innodb_file_per_table          | ON                     |

如果我从 MySQL CLI 手动更改 GLOBAL 设置,设置似乎会发生变化:

mysql> SET GLOBAL innodb_large_prefix = ON;
...
| innodb_large_prefix            | ON                     |

...但是当我尝试实际使用“大前缀”时,出现错误:

mysql> alter table [...]
ERROR 1709 (HY000): Index column size too large. The maximum column size is 767 bytes.

MySQL 的文档innodb_large_prefix setting说使用此设置有几个先决条件:

  1. MySQL 5.5.14 或更高版本 ✔
  2. innodb_file_format = 梭子鱼
  3. innodb_file_per_table = ON
  4. innodb_large_prefix = ON

经过一番尝试后,我可以通过以下方式根据需要转换我的表格:

  1. 设置全局 innodb_large_prefix = ON;
  2. ALTER TABLE [...], ROW_FORMAT=DYNAMIC;

太棒了。然后我再次重启MySQL并检查有效设置:

| innodb_large_prefix            | OFF                    |

我在使用该表等时没有出现任何错误,所以我想一切都很好,但奇怪的是设置似乎没有坚持下去。

我尝试将设置设置为 OFF 来重新更改我的表,但我无法构建那么大的索引。这是否意味着每当我想以这种方式更改表时,我都必须手动将 innodb_large_prefix 设置为 ON ?我是否没有在 /etc/mysql/my.cnf 中正确配置此设置?

最佳答案

有点隐蔽,但是根据documentation ,对于 MySQL < 5.6,您必须在配置文件中使用 1 而不是 ON:

Variables that have a type of “boolean” can be set to 0, 1, ON or OFF. (If you set them on the command line or in an option file, use the numeric values.)

对于 MySQL >= 5.6,您可以使用 ONOFF in the config files .

关于MySQL 5.5 innodb_large_prefix 配置设置未生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44708668/

相关文章:

mysql - UPDATE.. WHERE... - 交易可以在两者之间发生吗

php - 如何避免多对多查询中的 "Using temporary"?

mysql - 在 PhpMyadmin MySQL 中创建一个 UUID 字段

php - 正则表达式特殊字符是否允许安全漏洞?

mysql - 无法添加或更新子行: a foreign key constraint fails

mysql - 简单的 UPDATE 查询在 InnoDB 中比 MyISAM 花费更多时间

mysql - 外键与分区

PHP:迭代 SQL Return 的最佳方法

php - 在 LAMP 服务器上使用 PHP 从 MySQLi 输出 JSON api

php - 当前页面通过php更新Mysql中的数据