title: MySQL trims value in WHERE
body: <p>I didn't find a similar question maybe because I don't find the correct words (English is not my first language)</p>
  
  <h1>Problem</h1>
  
  <p>I have a <code>varchar</code> value that has a blank space at the end: <code>"opt-193-381-markets "</code> and when I do a <code>SELECT</code> with the value <strong>without</strong> the blank space, it returns the same result. It's like MySQL is trimming the value in the <code>WHERE</code></p>
  
  <p>Table definition:</p>
  
  <pre><code>mysql&gt; desc message;
  +------------+--------------+------+-----+---------+-------+
  | Field      | Type         | Null | Key | Default | Extra |
  +------------+--------------+------+-----+---------+-------+
  | FileId     | int(11)      | NO   | PRI | 0       |       |
  | MessageKey | varchar(100) | NO   | PRI |         |       |
  | NumericKey | tinyint(1)   | NO   |     | 0       |       |
  | IsObsolete | tinyint(4)   | YES  | MUL | NULL    |       |
  | notes      | text         | YES  |     | NULL    |       |
  +------------+--------------+------+-----+---------+-------+
  </code></pre>
  
  <p>Examples:</p>
  
  <pre><code>mysql&gt; SELECT * FROM message WHERE MessageKey = "opt-193-381-markets";
  +--------+----------------------+------------+------------+-------+
  | FileId | MessageKey           | NumericKey | IsObsolete | notes |
  +--------+----------------------+------------+------------+-------+
  |    304 | opt-193-381-markets  |          0 |          1 | NULL  |
  |    337 | opt-193-381-markets  |          0 |          1 | NULL  |
  +--------+----------------------+------------+------------+-------+
  </code></pre>
  
  <p>Notice that the <code>MessageKey</code> has the value with the blank space at the end and I just asked for the value without that blank space.</p>
  
  <pre><code>mysql&gt; SELECT * FROM message WHERE MessageKey = "opt-193-381-markets ";
  +--------+----------------------+------------+------------+-------+
  | FileId | MessageKey           | NumericKey | IsObsolete | notes |
  +--------+----------------------+------------+------------+-------+
  |    304 | opt-193-381-markets  |          0 |          1 | NULL  |
  |    337 | opt-193-381-markets  |          0 |          1 | NULL  |
  +--------+----------------------+------------+------------+-------+
  </code></pre>
  
  <p>Adding one more space</p>
  
  <pre><code>mysql&gt; SELECT * FROM message WHERE MessageKey = "opt-193-381-markets  ";
  +--------+----------------------+------------+------------+-------+
  | FileId | MessageKey           | NumericKey | IsObsolete | notes |
  +--------+----------------------+------------+------------+-------+
  |    304 | opt-193-381-markets  |          0 |          1 | NULL  |
  |    337 | opt-193-381-markets  |          0 |          1 | NULL  |
  +--------+----------------------+------------+------------+-------+
  </code></pre>
  
  <p>Escaping the spaces</p>
  
  <pre><code>mysql&gt; SELECT * FROM message WHERE MessageKey = "opt-193-381-markets\ \ ";
  +--------+----------------------+------------+------------+-------+
  | FileId | MessageKey           | NumericKey | IsObsolete | notes |
  +--------+----------------------+------------+------------+-------+
  |    304 | opt-193-381-markets  |          0 |          1 | NULL  |
  |    337 | opt-193-381-markets  |          0 |          1 | NULL  |
  +--------+----------------------+------------+------------+-------+
  </code></pre>
  
  <p>I've also tried with single quotes <code>'opt-193-381-markets'</code></p>
  
  <h1>Question</h1>
  
  <p>Why I cannot search for the exact value of <code>MessageKey</code>?</p>
  
  <p>Thanks</p>