Home >Database >Mysql Tutorial >How to make mysql query case sensitive
In mysql, you can use the select query statement with the binary keyword to distinguish case. The select statement is used to query data, and the binary keyword is used to distinguish case. The syntax is "select * from table name WHERE binary field = field value".
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
Query in mysql is case-sensitive by default, but it is not case-sensitive by default in mysql.
Solution:
mysql can add binary to the SQL statement to make it case-sensitive. BINARY is not a function, but a type conversion operator. It is used to force the string behind it to be a binary string. It can be understood that string comparison is case-sensitive.
1. Add binary
select * from users WHERE binary user_name = '张三' AND status != 0
to the query statement. 2. Add binary
create table t{ code varchar(10) binary }
ALTER TABLE t_order CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
when creating the table. After executing the above sql, the query of the table can be distinguished by size. wrote.
Recommended learning: mysql video tutorial
The above is the detailed content of How to make mysql query case sensitive. For more information, please follow other related articles on the PHP Chinese website!