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

马听 2025-06-18 10:59:33
昨天,一位朋友的数据库重启异常。

 

在错误日志中,有如下内容:

 

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数据库联盟(ID:gh_fbfc36d26181
dbaplus社群欢迎广大技术人员投稿,投稿邮箱:editor@dbaplus.cn
最新评论
访客 2024年04月08日

如果字段的最大可能长度超过255字节,那么长度值可能…

访客 2024年03月04日

只能说作者太用心了,优秀

访客 2024年02月23日

感谢详解

访客 2024年02月20日

一般干个7-8年(即30岁左右),能做到年入40w-50w;有…

访客 2023年08月20日

230721

活动预告