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

How to make mysql query case sensitive

WBOY
Release: 2022-02-15 10:39:32
Original
18994 people have browsed it

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
Copy after login

to the query statement. 2. Add binary

    create table t{
    code varchar(10)  binary
    }
Copy after login
ALTER TABLE t_order CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template