在Centos下安装Mysql后,发现执行SQL语句时区分大小写,大小写不一样就不能执行。
查询资料发现:
MySQL在Linux下数据库名、表名、列名、别名大小写规则是这样的:
- 数据库名与表名是严格区分大小写的;
- 表的别名是严格区分大小写的;
- 列名与列的别名在所有的情况下均是忽略大小写的;
- 变量名也是严格区分大小写的;
MySQL在Windows下都不区分大小写。
如果想在Linux下表名不区分大小写,以下是告诉你怎么解决此问题。
1、配置
找到Mysql配置文件my.cnf
vi /etc/my.cnf
在配置文件中增加以下内容
lower_case_table_names = 1#0:区分大小写,1:不区分大小写
注:
- 1、修改前必须先关闭服务,修改完成之后重启服务,就可以实现表名不区分大小写了。
- 2、增加的内容必须增加在[mysql]下面不能加到最后,否则不设置不成功。
2、验证是否配置成功
[root@iZ2zee0ipi05o1446ponmvZ ~]# mysql -uroot -p #登录mysqlEnter password: #输入登录密码Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 43Server version: 5.6.39 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show variables like "%case%"; #查看MySQL配置参数+------------------------+-------+| Variable_name | Value |+------------------------+-------+| lower_case_file_system | OFF || lower_case_table_names | 1 | #1表示不区分大小写,0表示区分大小写+------------------------+-------+2 rows in set (0.00 sec)