Detailed explanation of the problem of matching even when there is a space at the end of the string in the Mysql query condition

Detailed explanation of the problem of matching even when there is a space at the end of the string in the Mysql query condition

1. Table structure

TABLE person

id name
1 you
2 You (a space)
3 You (two spaces)

2. Query and Results

select * from person where `name` = ?

regardless? = "you + a few spaces", all three results will be retrieved.

3. Reasons

MySQL's collation rules are PADSPACE, which ignores trailing spaces.

It is aimed at text data types such as varchar char text...

This is SQL standardized behavior. No settings are required and cannot be changed.

4. What if you want to make an accurate query?

Method 1: like

select * from person where `name` like ?

Method 2: BINARY

select * from person where `name` = BINARY ?

BINARY is not a function, but a type conversion operator. It is used to force the string behind it to be a binary string, which can be understood as an exact match.

The above are all the relevant knowledge points introduced this time. If you have any additions, please contact the editor of 123WORDPRESS.COM.

You may also be interested in:
  • MySQL retrieves data based on the JSON field content as a query condition (including JSON arrays)
  • The difference and reasons between the MySQL query conditions not in and in
  • Detailed explanation of common usage of MySQL query conditions
  • Will the index be used in the MySQL query condition?
  • Analysis of the difference between placing on and where in MySQL query conditions
  • MySQL explains how to optimize query conditions

<<:  JavaScript using Ckeditor + Ckfinder file upload case detailed explanation

>>:  Using jQuery to implement the carousel effect

Recommend

How to add interface listening mask in Vue project

1. Business Background Using a mask layer to shie...

MySQL index coverage example analysis

This article describes MySQL index coverage with ...

How to use Docker to build a development environment (Windows and Mac)

Table of contents 1. Benefits of using Docker 2. ...

About using Alibaba's iconfont vector icon in Vue

There are many import methods on the Internet, an...

How to configure redis sentinel mode in Docker (on multiple servers)

Table of contents Preface condition Install Docke...

Linux installation Redis implementation process and error solution

I installed redis today and some errors occurred ...

How to use the Linux md5sum command

01. Command Overview md5sum - Calculate and verif...

How to deploy a simple c/c++ program using docker

1. First, create a hello-world.cpp file The progr...

Solve the problem of secure_file_priv null

Add secure_file_priv = ' '; then run cmd ...

Examples of using the Li tag in HTML

I hope to align the title on the left and the dat...

Example of implementing dashed border with html2canvas

html2canvas is a library that generates canvas fr...

A complete guide to clearing floats in CSS (summary)

1. Parent div defines pseudo-classes: after and z...