http://blog.chinaunix.net/u/29134/showart_355336.html MYSQL 在預設的情況下查詢是不區分 大小寫 的,例如: mysql create table t1( - name varchar(10)); Query OK, 0 rows affected (0.09 sec) mysql insert into t1 values('you'),('You'),('YOU'); Q
http://blog.chinaunix.net/u/29134/showart_355336.html
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: 0
mysql> 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系統不用修改,系統預設就是1
LINUX 系統預設是0。因為LINUX下的腳本都是區分大小寫的。
本條技術文章來源于網際網路,如果無意侵犯您的權益請點選此處回報版權投訴
本文系統來源:php中文網