暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL 8.0的这个参数千万别乱改!

113
昨天,一位朋友的数据库重启异常。
在错误日志中,有如下内容:

Different lower_case_table_names settings for server ('0') and data dictionary ('1')。


询问得知,是其他人改了 lower_case_table_names 这个参数。

lower_case_table_names参数的作用
lower_case_table_names控制着数据库对象的大小写敏感性和存储方式。可以配置成3个值:
0,表名按创建时指定的大小写存储,名称比较区分大小写;
1,表名按小写形式存储,名称比较不区分大小写;
2,表名按创建时指定的大小写存储,但以小写形式进行比较。

但MySQL 8.0开始,这个参数成了"一次性"设定!
这套MySQL的版本是 8.0.40。
MySQL 8.0 开始,是不让初始化之后修改 lower_case_table_names 的。
官方文档也有详细介绍:

https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_lower_case_table_names


取出关键的两段翻译一下:

It is prohibited to start the server with a lower_case_table_names setting that is different from the setting used when the server was initialized.  The restriction is necessary because collations used by various data dictionary table fields are determined by the setting defined when the server is initialized, and restarting the server with a different setting would introduce inconsistencies with respect to how identifiers are ordered and compared.

禁止使用与服务器初始化时使用的设置不同的lower_case_table_names设置启动服务器。这个限制是必要的,因为各种数据字典表字段使用的排序规则是由服务器初始化时定义的设置决定的,使用不同的设置重新启动服务器会导致标识符排序和比较方式的不一致

It is therefore necessary to configure lower_case_table_names to the desired setting before initializing the server.  In most cases, this requires configuring lower_case_table_names in a MySQL option file before starting the MySQL server for the first time.  

因此,有必要在初始化服务器之前将lower_case_table_names配置为所需的设置。在大多数情况下,这需要在第一次启动MySQL服务器之前在MySQL选项文件中配置lower_case_table_names。


一句话总结:8.0你敢改,MySQL就敢崩给你看


不过,MySQL 5.7是没有这个限制的,具体可以参考5.7对于这个参数的解释:

https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_lower_case_table_names


推荐的配置

所以,基于这个问题,还是建议大家在初始化数据库之前,就写在配置文件里。
Linux环境,建议是配置成1,也就是表名将以小写形式存储在磁盘上,并且比较不区分大小写。
MySQL 8.0的配置文件模板,可以跳转之前写的一篇文章:MySQL 8.0 配置文件模板

另外,我们创建了一个DBA学习小圈子:DBA驿站」星球。
加入星球,你将获得:
1 200+大厂DBA面试真题(带解析);
2 DBA工作中遇到的一些实战问题讨论;
3 送微信交流群。
感兴趣的,可以领取下方优惠券加入。

文章转载自MySQL数据库联盟,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论