大小写有关的参数介绍:
lower_case_file_system
该参数是用于描述data目录所在的操作系统是否为大小写敏感,该参数为bool类型,但无法修改。
0 -- 大小写敏感
1 -- 大小写不敏感
在linux上的都是OFF或者0,在windows下是ON或者0。
lower_case_table_names
该参数为静态,可设置为0、1、2。
# Specifies the on how table names are stored in the metadata.
# If set to 0, will throw an error on case-insensitive operative systems
# If set to 1, table names are stored in lowercase on disk and comparisons are not case sensitive.
# If set to 2, table names are stored as given but compared in lowercase.
# This option also applies to database names and table aliases.
0 -- 大小写敏感。(Unix,Linux默认)
表名存储为给定的大小和比较是区分大小写的 。
创建的库表将原样保存在磁盘上;SQL语句也会原样解析。
在大小写不敏感的系统上将出错,比如windows
1 -- 大小写不敏感。(Windows默认)
表名存储在磁盘是小写的,但是比较的时候是不区分大小写。
创建的库表时,MySQL将所有的库表名转换成小写存储在磁盘上;SQL语句同样会将库表名转换成小写。
如需要查询以前创建的Test_table(生成Test_table.frm文件),即便执行select * from Test_table,也会被转换成select * from test_table,致使报错表不存在。
2 -- 大小写不敏感(OS X默认)
创建的库表将原样保存在磁盘上。但SQL语句将库表名转换成小写
另外,如果在windows平台下,默认为1,也就是创建表不管怎么大小写组合,存储、显示、查询都是先转为小写执行;如果设置为2,则底层存储的XXX.frm
中XXX和一些编辑器是跟创建时,XXX.ibd是转为小写,大小写查询无影响
linux平台如果大小写不敏感,可以设置lower_case_table_names为1
lower_case_table_names这个参数设置完需要重启
如果之前的跟现在不一样,需要提前批量修改下大小写,或者导入导出
SELECT -- t2.table_schema,t2.table_name,t2.column_name,upper(t2.column_name),t2.column_type,
-- case when t2.is_nullable='NO' then 'not null' else 'null' end as isnull1,t2.column_comment,
CONCAT('ALTER table ',t2.table_schema,'.',t2.table_name,' CHANGE ',' \`',t2.column_name,'\` \`',UPPER(t2.column_name),'\` ',
t2.column_type,' ',CASE WHEN t2.is_nullable='NO' THEN 'not null' ELSE 'null' END,' COMMENT ''',t2.column_comment,''';') AS c
FROM information_schema.tables t1, information_schema.columns t2
WHERE t1.table_schema = 'db1'
AND t1.table_type = 'base table'
AND t1.table_schema = t2.table_schema
AND t1.table_name = t2.table_name