Back to Blog

MySQL Reserved Words Almost Ruined My Weekend

· 2 min read ·

Picture this: you export a MySQL dump, try to import it on another server, and it blows up. Why? Because someone (me, years ago) named a column status. Or order. Or key. You know, words that MySQL decided are sacred.

The fix is simple — wrap those column names in backticks. The annoying part is doing it manually on a 500MB dump file. No thanks.

So I built clean-sql. You point it at a SQL dump file and it fixes things automatically. What started as a backtick-quoting tool has grown to handle six different import errors: reserved words as column names, double-escaped quotes from buggy backup tools, trailing backslashes in values, foreign key constraint failures, null bytes, and literal newlines that confuse the mysql client.

It uses a character-level state machine that properly tracks single-quoted strings — even across multi-line HTML email templates with escaped quotes and CSS. So it only fixes actual column names, never corrupting content inside string values.

Could I have written a sed one-liner? Maybe. Would it have worked on edge cases? Absolutely not. I’ve been programming since 1988, I know better than to trust regex with SQL.

Built it in Go. Runs in seconds even on huge files — it shows a progress bar on big dumps and supports --check for dry runs, --disable-fk to wrap output with SET FOREIGN_KEY_CHECKS, and --update to self-update from GitHub.

GitHub repo

Loading comments...