title: Why are MySQL syntax error messages so bad?
body: <p>MySQL syntax errors are often pretty vague, only specifying the line where the error occurs. Writing a parser that produces accurate and useful error message is not completely trivial, but it's not an open research problem: most compilers for general purpose programming languages produce errors messages that are much more useful.</p>
  
  <p>So why doesn't MySQL's parser produce better error messages? Is it something to do with MySQL specifically, or the SQL grammar generally that makes this extremely difficult?</p>
  
  <p>Here's an example: </p>
  
  <pre><code>SELECT * FROM foo
  WHERE bar &gt; 0
  AND baz NOT NULL
  ORDER BY qux ASC
  </code></pre>
  
  <p>MySQL generates the following error message: <code>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL ORDER BY qux ASC'</code></p>
  
  <p>In fact, <code>NOT NULL</code> should be <code>IS NOT NULL</code>. So why doesn't MySQL generate an error like <code>Unexpected token NOT at line 3 column 8</code>?</p>