First create a test table:
Insert into Test (TT) Values ('\\\\172.18.28.153');
Now I want to use fuzzy matching to find out the string that starts with "\\172".
Need to use like because "\" is an escape character, so you need to use 4 "\". The statements are as follows:
SELECT * from where like ' \\\\172% ' ;
The result is that I can't get the data I want, which is supposed to be "\\172%" when the string is escaped and should get the result.
After many different attempts, the final successful statement is as follows:
SELECT * FROM test where TT like ' \\\\\\\\172% ';
The reasons for analysis may be as follows:
When MySQL resolves this statement, it escapes first, escaping two "\ \" to a "\"
The condition becomes: TT like ' \\\\172% '. Then, when the like statement is executed, it is escaped again, and the condition becomes: TT like ' \\172% '
The result is returned correctly.
All of this is speculation, because the behavior of the MySQL like statement is not well researched.
Mysql Fuzzy match and escape character