What is the SQL Minifier?
Minified SQL is handy when a query has to live on a single line: in an environment variable, a YAML or JSON config file, a log message, a shell command or a code string. The SQL Minifier strips -- and /* */ comments and collapses every run of spaces, tabs and line breaks, keeping only the spaces SQL needs between words.
It reads the SQL the way a database does, so text inside quotes (including things that look like comments), quoted identifiers in "double quotes", `backticks` or [brackets], and PostgreSQL $$ strings are left exactly as written. It also never joins two minus signs into a comment.
How to use it
- Paste SQL, upload a .sql file or click Example.
- Choose whether to keep MySQL /*! */ hints and whether to put each statement on its own line.
- Copy or download the minified SQL.
Example
-- Active users
SELECT id,
name -- display name
FROM users
WHERE status = 'active -- yes'
AND age >= 18;SELECT id,name FROM users WHERE status='active -- yes' AND age>=18;
Features
- Comment removal. Strips -- line comments and /* block comments */, and # comments for MySQL if you choose.
- String-safe. Quotes, quoted names and $$ strings are never changed.
- Keeps hints. Optionally keeps MySQL /*! */ version hints and /*+ */ optimizer hints.
- One statement per line. Useful for migrations and scripts that run line by line.
- Size saved. Shows how many characters and bytes were removed.
- Private. Runs in your browser; your SQL is never uploaded.
Frequently asked questions
Does minifying SQL make queries faster?
Not noticeably: databases ignore whitespace and comments when they parse a query. Minifying is about fitting SQL into one line or a smaller payload, not about speed.
Is it safe for stored procedures?
Yes for normal SQL, including PostgreSQL $$ function bodies. Be careful with scripts that rely on line breaks, such as SQL*Plus or psql meta-commands (lines starting with \ or /), and with DELIMITER changes in MySQL scripts.
What are MySQL /*! */ comments?
They are version hints: MySQL runs the code inside, while other databases treat it as a comment. mysqldump uses them a lot, so keep hints on when minifying a dump you will import into MySQL.
Last updated · Free, no sign-up, runs in your browser.