The basic lexer seems to be implemented in sql/sql_lex.cc. You could use/salvage this to build your own test parser.
But this would only check for syntax but not any runtime errors.
edit: For MySQL 8.0+ see How can I check the SQL syntax in a .sql file?