Home >Database >Mysql Tutorial >How to make mysql query case sensitive

How to make mysql query case sensitive

WBOY
WBOYOriginal
2022-02-15 10:39:3218988browse

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".

How to make mysql query case sensitive

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How is mysql query case-sensitive?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn