Format a MySQL Query Online
Paste a MySQL statement and get clause-per-line indentation, joins broken onto their own lines, and optional keyword uppercasing. Backtick-quoted identifiers are left exactly as you wrote them.
SQL Formatter
LOCAL · Browser-OnlyFormat and beautify SQL queries with proper indentation
Quick Start
- 1Paste your MySQL query into the editor
- 2Set keyword case to uppercase, lowercase, or preserve
- 3Choose leading or trailing commas and a 2 or 4 space indent
- 4Click Format, then copy the rewritten query
What This Tool Does
Formatting rewrites the query in place in the editor. Each major clause (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT and the rest) starts on its own line, every join gets a line of its own, and ON, AND, OR and the CASE keywords are indented one level under whatever they belong to. Parentheses drive the indent, so a subquery steps in and then back out.
Backtick-quoted identifiers are recognized and left exactly as written, which is what makes this practical on MySQL specifically: a column called order, key or status survives a pass that would otherwise treat it as a keyword. Single-quoted strings and comments are protected the same way.
Three controls shape the result: keyword case set to uppercase, lowercase or preserved; comma placement, which decides whether a column list reads with the comma at the end of each line or at the start of the next; and a two or four space indent. Minify does the reverse and collapses the statement back onto one line.
Limits Worth Knowing
- Formatting replaces the text in the editor and there is no undo, so copy anything you cannot regenerate before you press it.
- There is no dialect selector. The formatter recognizes backtick quoting by its syntax rather than by a mode you switch on.
- Keyword casing comes from a fixed keyword list, so an unquoted column named date, format or left will be recased. Backtick it, or set Keywords to Preserve.
- Nothing is validated. A query with a syntax error is reformatted just as happily as a correct one.
- Line comments force a line break, so a heavily commented query will not collapse fully when minified.
Common Questions
Will it change what my query does?
How do I stop it uppercasing a column name?
Can I format several statements at once?
More Format Tools
All formatters →Format a SQL Server Query Online
Pretty print T-SQL from a profiler or log into clause-per-line SQL. Free SQL Server formatter with keyword casing and comma style.
Format an XML Document Online
Beautify and validate XML with chosen indentation. Free XML formatter that flags well-formedness errors by line, no signup.
Format JavaScript Online
Beautify and reindent messy or minified JavaScript with consistent formatting. Free online JavaScript formatter that runs in your browser.
Format & Beautify JSON Online
Paste minified or messy JSON and format it with proper indentation. Free online JSON formatter with validation.
Format SQL Queries Online
Beautify and indent SQL queries for better readability. Free online SQL formatter supporting MySQL, PostgreSQL, and more.
Format & Beautify XML Online
Paste XML data and format it with proper indentation and syntax highlighting. Free online XML formatter and validator.
Looking for FAQs and advanced options? Visit the full SQL Formatter page →