Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do you escape a question mark character in a string on the MySQL CLI?

There are many methods to avoid having to escape characters, but from an ease-of-use perspective I would quite like to do some SELECT statements containing LIKE queries, some of which contain question marks and the usual \? does not work.

share|improve this question
up vote 0 down vote accepted

LIKE doesn't use ?. LIKE uses % and _.

share|improve this answer
Same question with a WHERE = then. – Metalshark Dec 8 '10 at 14:33
= doesn't use any wildcards. – Ignacio Vazquez-Abrams Dec 8 '10 at 14:35
I am looking for the string <a href="/about?param=value"> in a CMS. Performing SELECT uid FROM cms_table WHERE html LIKE '%/about%' works, however SELECT uid FROM cms_table WHERE html LIKE '%/about?%' doesn't. I cannot seem to escape the question mark and make it part of the statement. The same thing happens when using a plain WHERE =. – Metalshark Dec 8 '10 at 14:39
Thank you! There is something weird going on with this database, I'll look at character encodings... – Metalshark Dec 8 '10 at 14:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.