MySQL formatter
Format MySQL and MariaDB queries in your browser. Backticks, # comments, @variables and JSON operators are read MySQL's way, and nothing you paste is uploaded.
Every layout setting of the formatter, grouped like Editor › Formatting in the SQLly app. The style above is the starting point; anything you change here is marked.
Drop a .sql file here to open it. It is read in your browser, not uploaded.
# monthly revenue by channel
SELECT
DATE_FORMAT(o.`created_at`, '%Y-%m') AS `month`,
o.meta ->> '$.channel' AS channel,
SUM(oi.`qty` * oi.`price`) AS revenue
FROM
`orders` o
JOIN `order_items` oi ON oi.`order_id` = o.`id`
WHERE
o.`status` = "paid"
AND o.`customer_id` <=> @customer
GROUP BY
`month`,
channel
ORDER BY
`month` DESC
LIMIT 12;
Loading the formatter…
Shortcuts in the editor: Ctrl+Enter formats and Ctrl+Shift+Enter minifies (⌘ instead of Ctrl on a Mac). Your settings are remembered in this browser and kept in the page address, so a link shares your style – never your SQL.
What the formatter does with MySQL SQL
- Backticks and strings.
`order`is a quoted name and"paid"is a string, as in MySQL's default SQL mode. Always quote adds backticks. - Every comment style is kept.
#comments,--comments and/*! … */executable comments stay where you wrote them. MySQL needs a space after--, and the formatter follows the same rule. - Variables are names.
@rankuser variables,@@sql_modesystem variables and:=assignments are read as single tokens. - JSON and null-safe operators stay whole.
->,->>and<=>are never split into- >>or<= >, which would no longer run. - Literals keep their prefix.
b'0101',x'ff',N'…'and character-set introducers such as_utf8mb4'…'stay attached, so they are never read as a column with an alias. - Case-safe quoting. Table names can be case-sensitive on Linux, so Remove unnecessary quotes only unquotes lowercase names.
Good to know
- By default MySQL rejects a space between built-in functions such as
COUNTorSUMand their parenthesis. The formatter writesCOUNT(*)and Minify keeps calls as you wrote them; only turn on Space before function parentheses if your server runs withIGNORE_SPACE.
Examples
MySQL before and after
# monthly revenue by channel select date_format(o.`created_at`,'%Y-%m') as `month`,o.meta->>'$.channel' as channel,sum(oi.`qty`*oi.`price`) as revenue from `orders` o join `order_items` oi on oi.`order_id`=o.`id` where o.`status`="paid" and o.`customer_id`<=>@customer group by `month`,channel order by `month` desc limit 12;
# monthly revenue by channel
SELECT
DATE_FORMAT(o.`created_at`, '%Y-%m') AS `month`,
o.meta ->> '$.channel' AS channel,
SUM(oi.`qty` * oi.`price`) AS revenue
FROM
`orders` o
JOIN `order_items` oi ON oi.`order_id` = o.`id`
WHERE
o.`status` = "paid"
AND o.`customer_id` <=> @customer
GROUP BY
`month`,
channel
ORDER BY
`month` DESC
LIMIT 12;
The output uses the Standard style with 4-space indents, exactly as the formatter above produces it. Switch the style to Compact for denser SQL or Expanded for leading commas and one item per line. The formatter docs cover the details.
MySQL formatter FAQ
Does it work for MariaDB?
Yes. MariaDB uses the same quoting, comment and variable syntax, and /*M! … */ executable comments are kept like MySQL's /*! … */ ones.
Will Minify drop my /*! … */ executable comments?
No. Minify drops ordinary comments but keeps executable comments and optimizer hints, because the server runs what is inside them.
Why does the formatter write COUNT(*) without a space?
Because MySQL, unless the IGNORE_SPACE SQL mode is on, does not accept whitespace between COUNT, SUM and some other built-in functions and the opening parenthesis.
Is my SQL sent to a server?
No. The formatter is compiled to WebAssembly and runs inside your browser tab. Your SQL is never uploaded, logged or stored, and once the page has loaded it keeps working offline.
Can formatting break my query?
It is built not to. After formatting, SQLly checks its output token by token against your input. If anything other than whitespace and the casing you asked for would change, it gives your SQL back exactly as you wrote it and tells you why. SQL that does not parse cleanly, such as an unterminated string, is also left untouched, with the line and column of the problem.
Can I share my formatting settings with my team?
Yes. Every setting, including the advanced ones, is kept in the page address after the # sign, so copying the address or pressing Copy settings link shares your exact style. The link holds the settings only, never your SQL.
Other dialects
- Any dialect (auto-detect)
- SQL Server formatter (T-SQL)
- PostgreSQL formatter
- SQLite formatter
- Oracle SQL formatter
- Snowflake SQL formatter
- BigQuery SQL formatter
- Redshift SQL formatter
Working with MySQL every day? See what the SQLly desktop app does for MySQL, or browse all features.
Like the formatter? Meet the rest of SQLly
A native SQL workbench for macOS, Windows and Linux with IntelliSense that knows your schema, guardrails for risky queries, and this formatter built into the editor.