MySQL8 里面表名称大小写敏感的问题

lower_case_file_system是一个只读参数,无法被修改,这个参数是用来告诉你在当前的系统平台下,是否对文件名大小写敏感。

lower_case_table_names:

    为0时大小写敏感,表名称大小写与给定的一致,对比的时候大小写敏感

    为1时大小写不敏感,表名称保存为小写,对比时大小写不敏感

    为2时大小写不敏感,但是保存的表名称与给定的大小写一致,只是对比的时候都转换成小写进行对比

lower_case_table_names的默认值在不同操作系统不一样:

    macOS:2

    Unix:0

    Windows:1

在配置文件中直接设定此值可能会导致MySQL无法启动,解决方法见:https://blog.csdn.net/weixin_33805743/article/details/94292365

 

另外,在window下,lower_case_table_names无法设置为0,只能是1或者2,否则启动时会报错:

The server option 'lower_case_table_names' is configured to use case sensitive table names but the data directory is on a case-insensitive file system which is an unsupported combination. Please consider either using a case sensitive file system for your data directory or switching to a case-insensitive table name mode.

因为window文件系统大小写不敏感

 

 

更详细的说明:https://zhuanlan.zhihu.com/p/606877902

系统变量lower_case_table_names有三个值:分别是0、1、2.
1. 设置成0:表名按你写的SQL大小写存储,大写就大写小写就小写,比较时大小写敏感。
  例如:代码里访问select * from ACT_EVT_LOG;执行的时候就是访问ACT_EVT_LOG这张表。
       代码里访问select * from act_evt_log;执行的时候就是访问act_evt_log这张表。
2. 设置成1:表名转小写后存储到硬盘,比较时大小写不敏感。 
  例如:代码里访问select * from ACT_EVT_LOG;或者select * from act_evt_log;执行的时候都是访问act_evt_log这张表。
3. 设置成2:表名按你写的SQL大小写存储,大写就大写小写就小写,比较时统一转小写比较。
    例如:代码里访问select * from ACT_EVT_LOG;执行的时候就是访问act_evt_log这张表。




感觉将lower_case_table_names设置为2或者3都可以,最终在执行的时候效果都是大小写敏感,为1时直接大小写不敏感,为2时统一转小写比较,效果也是大小写不敏感,只在保存时有差别,为1时统一保存为小写,为2时保存大小写与sql中的一致