mysql大小写

时间:2021-06-17 17:06:18   收藏:0   阅读:0

查看是否区分大小写

show Variables like ‘%table_names‘

查看lower_case_table_names的值,0代表区分,1代表不区分

 

修改方法

1.用ROOT登录,修改/etc/my.cnf

2.在[mysqld]下加入一行:lower_case_table_names=1

3.重新启动数据库即可。

 

参数详解

其中0:区分大小写,1:不区分大小写

 

MySQL在Linux下数据库名、表名、列名、别名大小写规则是这样的:

1、数据库名与表名是严格区分大小写的;

2、表的别名是严格区分大小写的;

3、列名与列的别名在所有的情况下均是忽略大小写的;

4、变量名也是严格区分大小写的;

MySQL在Windows下都不区分大小写。

 

mysql默认是对字母的大小写不区分的

 

mysql> create table t1(

-> username varchar(10));

Query OK, 0 rows affected (0.09 sec)

 

mysql> insert into t1 values(‘you‘),(‘You‘),(‘YOU‘);

Query OK, 3 rows affected (0.05 sec)

Records: 3 Duplicates: 0 Warnings: 0

对这个表,缺省情况下,下面两个查询的结果是一样的:

 

mysql> select * from t1 where username = ‘you‘;
+------+
| username |
+------+
| you |
| You |
| YOU |
+------+
3 rows in set (0.00 sec)
mysql> select * from t1 where username = ‘YOU‘;
+------+
| username |
+------+
| you |
| You |
| YOU |
+------+
3 rows in set (0.00 sec)

如果想让MYSQL知道你输入的字母是大写还是小写的,修改表:

mysql> alter table t1 change username username varchar(10) binary;
Query OK, 3 rows affected (0.20 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from t1 where username = ‘you‘;
+------+
| username |
+------+
| you |
+------+
1 row in set (0.00 sec)
mysql> select * from t1 where username = ‘YOU‘;
+------+
| username |
+------+
| YOU |
+------+
1 row in set (0.00 sec)

如果你只是想在SQL语句中实现的话:

mysql> select * from t1 where username = binary ‘YOU‘;
+------+
| username |
+------+
| YOU |
+------+
1 row in set (0.02 sec)
mysql> select * from t1 where username = binary ‘you‘;
+------+
| username |
+------+
| you |
+------+
1 row in set (0.00 sec)

 

 

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!