SQL String Sanitizer
Escape quotes and special characters for safe use in SQL queries — prevents SQL injection
Paste any raw string, pick your SQL dialect, and get back a properly escaped version safe to drop into queries. Single quotes get doubled, backslashes get handled per-dialect, and wildcards are escaped for LIKE clauses when you turn that on. And everything runs in your browser. Nothing gets uploaded.
How It Works
The tool scans your input character by character. Single quotes get doubled (' becomes ''), backslashes get escaped in MySQL mode, and wildcards like % and _ get prefixed with a backslash when that option is on. Each SQL dialect has slightly different rules — PostgreSQL and SQLite just double quotes, while MySQL also escapes backslashes because it treats \ as an escape character by default.
Examples
Name with an Apostrophe
The classic scenario — inserting a name like O'Brien into a user table.
Conan O'Brien
Conan O''Brien
Escaping a Malicious Injection Attempt
Someone typed a classic SQL injection payload into your search field. Here's what the sanitizer does with it.
'; DROP TABLE users; --
'''; DROP TABLE users; --
The single quote gets doubled, so the entire string stays inside the literal. The DROP TABLE never executes — it's just text now.
MySQL String with Backslashes and Wildcards
A file path with backslashes going into a MySQL LIKE clause — two things need escaping at once.
C:\Users\100%_done
C:\\Users\\100\%\_done
Backslashes get doubled for MySQL, and % and _ are escaped so the LIKE clause treats them as literal characters instead of wildcards.
Who Uses This
Sanitizing user input for ad-hoc migration scripts and seed data files that bypass the ORM.
Building INSERT/UPDATE statements in query editors when fixing production data by hand.
Learning how SQL injection works and what proper escaping actually looks like under the hood.
Verifying that application inputs are properly escaped before running penetration tests.
Common Mistakes
String escaping is a fallback, not a strategy. If your app talks to a database through code, use prepared statements. Every language has them. This tool is for manual SQL work — scripts, data dumps, quick fixes in a query client.
MySQL treats backslashes as escape characters. PostgreSQL does not. If you sanitize for PostgreSQL but run the query on MySQL, backslashes slip through unescaped. Always match the dialect to your actual database engine.
You sanitized the quotes but left % and _ alone. Now your LIKE search matches way more rows than expected because those characters act as wildcards. Turn on "Escape wildcards" when you're building a LIKE expression.
Technical Details
- Processing: 100% client-side — nothing leaves your browser
- Supported Dialects: MySQL, PostgreSQL, SQL Server, SQLite
- Escaping Targets: Single quotes, backslashes, wildcard characters (
%,_) - Browser Support: Chrome, Firefox, Safari, Edge
- Output: Copy to clipboard or download as
.sqlfile
Frequently Asked Questions
What is SQL string sanitization?
It's the process of escaping special characters — mainly single quotes — so they're treated as plain text inside a SQL query instead of as SQL syntax. Without it, a stray apostrophe can break your query or, worse, let someone inject malicious SQL commands.
Should I use this instead of parameterized queries?
No. Parameterized queries (prepared statements) are the right choice for any production application. This tool is meant for manual work — writing migration scripts, fixing data in a database client, or generating SQL dump files where you can't use bind parameters.
Why does MySQL escaping differ from PostgreSQL?
MySQL treats the backslash as an escape character by default, so \n inside a string means a newline, not a literal backslash followed by 'n'. PostgreSQL follows the SQL standard more closely and doesn't give backslashes special meaning. That's why MySQL needs both quote doubling and backslash escaping.
When do I need to escape wildcard characters?
Only when your string goes inside a LIKE clause. The % and _ characters are wildcards in LIKE patterns — % matches any sequence, _ matches one character. If you're doing a regular INSERT or WHERE equals comparison, you don't need to escape them.
Is my data safe using this online tool?
Yes. The entire thing runs in JavaScript inside your browser. Nothing gets sent to a server. You can disconnect from the internet and it still works — that's the easiest way to verify. Your strings stay on your machine and disappear when you close the tab.