Windows中MySql区分大小写的表名称的奇怪行为

前端之家收集整理的这篇文章主要介绍了Windows中MySql区分大小写的表名称的奇怪行为前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的 Windows机器上,当我使用以下查询MysqL中选择表名时,我得到的表名称区分大小写.

@H_502_8@

@H_502_8@

MysqL> select table_schema,table_name 
from information_schema.tables where table_schema='test';
+--------------+------------+
| table_schema | table_name |
+--------------+------------+
| test         | TableOne   |
| test         | TableTwo   |
+--------------+------------+
2 rows in set (0.00 sec)

但是当我按表名选择时,我得到了不同的结果.@H_502_8@

@H_502_8@

MysqL> select table_schema,table_name from information_schema.tables 
where table_schema='test' and table_name = 'TableOne';
+--------------+------------+
| table_schema | table_name |
+--------------+------------+
| test         | tableone   |
+--------------+------------+
1 row in set (0.00 sec)

让它更奇怪的是这个.@H_502_8@

@H_502_8@

MysqL> select table_schema,table_name from information_schema.tables 
where table_schema='test' and table_name like 'TableOne';
+--------------+------------+
| table_schema | table_name |
+--------------+------------+
| test         | TableOne   |
+--------------+------------+
1 row in set (0.00 sec)

解决方法

有一个名为lower_case_table_names的MysqL变量.当此项设置为0时,表名称区分大小写.但是不建议像Windows一样不区分大小写的机器.下一个选项是1.在此选项中,所有表名称甚至在存储之前都会转换为小写.在这种情况下,您将始终获得小写表名称.在我的例子中,这个变量的值设置为2.在这种情况下,MysqL存储表名,但是当我们比较表名时,它会将它们转换为小写并进行比较.

@H_502_8@

所以在第一种情况下,表名不进行比较,因此我们得到原始值.@H_502_8@

在第二种情况下,我们比较表名,所以MysqL将表名转换为小写进行比较.但奇怪的是,他们正在返回转换后的值,而不是原始值.@H_502_8@

最后在第三种情况下,我们使用like运算符本身不区分大小写,因此MysqL不打算将表名转换为小写,我们得到原始结果.@H_502_8@

猜你在找的Windows相关文章