在MySQL中选择一些特殊字符时的奇怪行为

I have a row, which have column url with the following value:

http://example.com/a~~1234567890-=!@#$%^&*()_+[\"test\"]

When I execute the following query:

SELECT * FROM `mytable` WHERE `url` = 'http://example.com/a~~1234567890-=!@#$%^&*()_+[\"test\"]'

MySQL says that record is not exists.

You need to escape the \ in your two \" since \" is an escape sequence: only the quote " will remain in the executed query.

\" [is an escape sequence turned into a] double quote (“"”) character
\\ [is an escape sequence turned into a] backslash (“\”) character

http://dev.mysql.com/doc/refman/5.7/en/string-literals.html

So

SELECT * FROM `mytable` WHERE `url` = 'http://example.com/a~~1234567890-=!@#$%^&*()_+[\\"test\\"]'