您好,欢迎访问一九零五行业门户网

MYSQL在默认的情况下查询不区分大小写

mysql在默认的情况下查询是不区分大小写的,例如: mysql create table t1( - name 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
mysql在默认的情况下查询是不区分大小写的,例如:mysql> create table t1(    -> name 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 name = 'you';+------+| name |+------+| you  || you  || you  |+------+3 rows in set (0.00 sec)mysql> select * from t1 where name = 'you';+------+| name |+------+| you  || you  || you  |+------+3 rows in set (0.00 sec)
如果想让mysql知道你输入的字母是大写还是小写的,修改表:mysql> alter table t1 change name name varchar(10) binary;query ok, 3 rows affected (0.20 sec)records: 3  duplicates: 0  warnings: 0mysql> select * from t1 where name = 'you';+------+| name |+------+| you  |+------+1 row in set (0.00 sec)mysql> select * from t1 where name = 'you';+------+| name |+------+| you  |+------+1 row in set (0.00 sec)
如果你只是想在sql语句中实现的话:mysql> select * from t1 where name = binary 'you';+------+| name |+------+| you  |+------+1 row in set (0.02 sec)mysql> select * from t1 where name = binary 'you';+------+| name |+------+| you  |+------+1 row in set (0.00 sec)
如果不想这么麻烦而想服务一开启就让大小写一致的话:可以修改my.ini或者my.cnf[mysqld] lower_case_table_names=1(0:区分;1:不区分)然后重启mysql服务。mysql> show variables like '%case_table%';+------------------------+-------+| variable_name          | value |+------------------------+-------+| lower_case_table_names | 1     |+------------------------+-------+1 row in set (0.00 sec)注:windows系统不用修改,系统默认就是1linux 系统默认是0。因为linux下的脚本都是区分大小写的。  原文地址:mysql在默认的情况下查询不区分大小写, 感谢原作者分享。
其它类似信息

推荐信息