mysql大小问题

大小写有关的参数介绍:

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

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

朝闻道-夕死可矣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值