Skip to content

bytebase/mysql-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The mysql-parser is a parser for MySQL. It is based on the ANTLR4 and use the grammar from antlr4-grammars-mysql.

Build

Before build, you need to install the ANTLR4.

requirements:

./build.sh

Update grammar

Manually change the grammar file in this project

  1. run ./build.sh to generate the parser code.

From antlr4-grammars-mysql

  1. Clone the MySQLLexer.g4 and MySQLParser.g4 grammar files from https://github.com/mysql/mysql-workbench/tree/8.0/library/parsers/grammars.
  2. Update the lexer and parser.
  3. run ./build.sh to generate the parser code.

Updates from MySQL Workbench.

  1. Removed the version checks https://github.com/bytebase/mysql-parser/commit/addcea9f8779ffe95159e334d9dd1ea7f93ed32d.
  2. Used SQL Mode off by default, and removed set types https://github.com/bytebase/mysql-parser/commit/878f24d9fd313f60b3a10f977c489c0599ae2d49, https://github.com/bytebase/mysql-parser/commit/1062be07340ebc148c7119cd16e980792eeb1653.
  3. Hacked dot identifier and removed the base class of lexer and parser https://github.com/bytebase/mysql-parser/commit/1d535c32a0be05d14ffc333f08f9a17d375ce922.
  4. Follow the change logs below to update the grammar.

Test the parser

Run TestMySQLDBSQLParser in parser_test.go to test the parser.

go test -v

References

Change Logs

  • 2023-06-05: Support 8.0 CREATE USER statement, specifically the [COMMENT 'comment_string' | ATTRIBUTE 'json_object'] clause.