MySQL Query Formatter
Paste one or more MySQL or MariaDB statements and get them formatted with consistent indentation and keyword case, parsed with the MySQL grammar so backtick identifiers, INTERVAL arithmetic and ON DUPLICATE KEY UPDATE are understood. A compatibility check points out syntax copied from other databases, such as ILIKE, :: casts, FULL OUTER JOIN or ||, along with UPDATE and DELETE statements without a WHERE clause.
- Runs in your browser
- No sign-up
- Free to use
How to use MySQL Query Formatter
- Paste your MySQL query or open a .sql file.
- Choose MySQL or MariaDB, keyword case and indentation.
- Click Format and read any compatibility warnings.
- Copy or download the formatted SQL.
MySQL Query Formatter features
MySQL grammar
Backticks, INTERVAL, ON DUPLICATE KEY UPDATE and MySQL functions.
MariaDB mode
Formats MariaDB-specific syntax correctly.
Case control
Keywords and functions upper, lower or as written.
Compatibility check
Flags PostgreSQL and SQL Server syntax MySQL does not accept.
Safety check
Warns about UPDATE and DELETE without WHERE and = NULL comparisons.
Multiple statements
Each statement formatted, with chosen spacing between them.
When to use MySQL Query Formatter
- Cleaning up a long query before a code review.
- Porting a query from PostgreSQL to MySQL and finding what must change.
- Making slow-query-log entries readable.
- Formatting migration files consistently.
MySQL Query Formatter FAQ
How is this different from a general SQL formatter?
It formats with MySQL’s grammar and checks the query against MySQL’s rules, so syntax from other databases is reported instead of silently formatted.
What does the compatibility check look for?
PostgreSQL casts (::), ILIKE, ON CONFLICT and RETURNING, SQL Server TOP, GETDATE(), square brackets and OFFSET … FETCH, || used as concatenation, FULL OUTER JOIN and more, each with the MySQL alternative.
Why is || a problem?
In MySQL’s default mode || means logical OR, so a || b returns 0 or 1 instead of joining strings. Use CONCAT(a, b).
Does formatting change what the query does?
No. Only whitespace and the case of keywords change; identifiers, strings and values stay as written.
Is the query executed?
No. It is only parsed and formatted in your browser.
Can I format stored procedures?
Simple procedures work, but DELIMITER commands used by the mysql client are not SQL and should be removed first.
Readable, portable MySQL
SQL is easy to write as one long line and hard to read that way. Consistent formatting puts each clause on its own line, indents joins and conditions, and uses one style for keywords, which makes queries quicker to review and diffs smaller. This formatter uses the MySQL grammar of the sql-formatter library, so MySQL-specific syntax such as backtick-quoted names, INTERVAL expressions and ON DUPLICATE KEY UPDATE is understood rather than mangled.
MySQL and MariaDB share most syntax but not all of it, so you can choose the flavour. Keyword case and function case are separate options: many teams write keywords in upper case and functions in lower case, others prefer everything in one case.
The compatibility check is what makes this tool specific to MySQL. Queries are often copied from documentation, Stack Overflow or another project that uses PostgreSQL or SQL Server. The check scans the query, ignoring strings and comments, for constructs that MySQL rejects or interprets differently: :: casts, ILIKE, FULL OUTER JOIN, ON CONFLICT, RETURNING, TOP, GETDATE(), ISNULL with two arguments, STRING_AGG and OFFSET … FETCH, and suggests the MySQL equivalent for each.
Some differences are silent, which makes them dangerous. In MySQL’s default SQL mode, || is the logical OR operator, so an expression meant to concatenate strings returns 0 or 1. The checker flags it and recommends CONCAT.
General safety checks apply as well: an UPDATE or DELETE without a WHERE clause changes every row, comparisons with = NULL are never true, and NOT IN with a subquery returns nothing when the subquery yields a NULL. Each warning includes the line number so you can find it in the formatted output.