Home/Dev Tools/MySQL Formatter

MySQL Formatter

Format

Format MySQL-flavored SQL with MySQL-specific syntax support.

Dialect
Keywords
Indent
Options
Input
Loading editor…
Output
Loading editor…
✨ AI Code Explanation
Mode

What Is a MySQL Formatter?

A MySQL formatter rewrites MySQL (and MariaDB) queries with consistent indentation, keyword casing, and clause alignment. It understands MySQL-specific syntax including backtick identifiers (`column`), LIMIT … OFFSET, ON DUPLICATE KEY UPDATE, STRAIGHT_JOIN, and the RAND()/NOW() function family. Formatted MySQL is dramatically easier to read, debug, and review.

MySQL Formatter Online — What This Tool Does

This free MySQL formatter beautifies MySQL queries entirely in your browser using the sql-formatter library with the MySQL dialect preset. Supports keyword casing (UPPER/lower/preserve), 2/4/tab indent, and comment stripping. Runs entirely locally — your queries never leave your machine.

How to Format MySQL Queries

  • Paste your MySQL or MariaDB query into the Input pane, or click Upload to load a .sql file.
  • Confirm the dialect is MySQL (selected by default for this route).
  • Pick keyword case — ABC (uppercase, standard), abc (lowercase), or (preserve original).
  • Pick indent: 2 spaces, 4 spaces, or tab.
  • Optional: enable No comments to strip -- and /* */ comments first.
  • Click Format. The formatted query appears in the output pane.
  • Click Copy or Download.

MySQL-Specific Syntax Handled

  • Backtick identifiers`order` for reserved words used as column names.
  • LIMIT … OFFSET — paginated result clauses.
  • ON DUPLICATE KEY UPDATE — upsert syntax unique to MySQL.
  • INSERT IGNORE — silently skip duplicate-key conflicts.
  • STRAIGHT_JOIN, FORCE INDEX — optimiser hints specific to MySQL.
  • Storage engine hintsENGINE=InnoDB in DDL.

MySQL vs PostgreSQL Formatting Differences

MySQL uses backticks for identifiers; PostgreSQL uses double-quotes. MySQL has LIMIT … OFFSET and ON DUPLICATE KEY UPDATE; PostgreSQL has LIMIT + OFFSET on separate lines and ON CONFLICT. Always pick the matching dialect — formatting MySQL with the PostgreSQL preset can mangle backtick identifiers and unrecognised reserved words.

Common Use Cases

  • Code review — format auto-generated MySQL from ORMs (Doctrine, Eloquent, Sequelize) for human review.
  • Stored procedure cleanup — beautify legacy stored procs before refactoring.
  • Migration scripts — format migrations before merging to keep diffs clean.
  • Onboarding — format unfamiliar queries for easier learning.

Tips & Tricks

  • Uppercase keywords for the SQL standard look — most MySQL conventions use SELECT, FROM, WHERE in UPPER.
  • Test in MySQL Workbench — paste the formatted output to verify execution.
  • Strip comments before sharing in tickets — internal comments may contain sensitive context.
  • Use the SQL Minifier when embedding queries in code.

Related Tools

Is My SQL Sent to a Server?

No. MySQL formatting runs entirely in your browser using the sql-formatter library. Your queries — including any production credentials, table names, or business logic — never leave your machine.