Loading SQL to Base64 Converter...

How to Convert SQL to Base64

Step 1

Add your SQL

Paste a query or a whole script, upload a .sql file, or click Sample to load a small CREATE TABLE with two INSERT statements.

•
Paste directly: copy a query from your database client, a migration file or a pull request
•
Upload a file: click "Upload" and pick a .sql or .txt file; it is read as raw bytes
•
Try the sample: click "Sample" to see how a short schema script looks once encoded
Step 2

Read the Base64

About a third of a second after you stop typing, the Base64 string appears in the output panel. If a quoted string or comment is never closed, a note above the editor points to where it starts, and the text is still encoded as typed. The output is standard RFC 4648 Base64 with +, / and = padding, on one line, the same as base64 -w0 seed.sql gives you.

•
No Convert button: the output follows the editor as you type
•
Cut-off scripts: an unclosed string, quoted name or comment is pointed out by line and column, and still encoded as typed
•
Exact bytes: accents, emoji and long IDs such as 8901240544102066246 decode back unchanged
Step 3

Copy or download it

Click Copy to put the string on your clipboard, or Download to save it as encoded-base64.txt. Both always use what is in the editor at that moment, ready to paste into a CI variable, a ConfigMap or a JSON field.

•
CI pipelines: keep a seed script in one variable and run echo "$SEED_SQL" | base64 -d | psql
•
Kubernetes: paste it under binaryData in a ConfigMap or under data in a Secret for an init container
•
JSON payloads: send a migration to an API without escaping every quote and line break

What is SQL to Base64 Encoding?

SQL (Structured Query Language) to Base64 encoding rewrites a query as plain ASCII so it can pass through places that would otherwise mangle it. Single quotes, semicolons, backslashes and line breaks are exactly the characters that shell variables, YAML files and JSON strings treat specially.

The page uses the TextEncoder API to turn your SQL into UTF-8 bytes and then encodes those bytes in chunks, so even a multi-megabyte dump works. Keep in mind that Base64 is reversible by anyone: it makes a script easy to carry, not secret.

Frequently Asked Questions

Why would anyone put SQL in Base64?

Because SQL is full of characters other formats treat as special. A seed script stored in a CI variable, a migration shipped inside a JSON request body, or an init script mounted from a Kubernetes ConfigMap or Secret can all break on a stray single quote, a semicolon or a line break. Base64 turns the whole script into letters, digits, +, / and =, so it travels through YAML, JSON and shell variables untouched and is decoded right before it runs.

Will my query come back exactly the same?

Yes. The SQL is turned into UTF-8 bytes and only those bytes are encoded. Comments, blank lines, CRLF line endings, quoted strings such as 'it''s' and values like 8901240544102066246, '00501' or 14.50 decode back character for character. For example, SELECT * FROM sims WHERE zip = '00501'; followed by a line break becomes U0VMRUNUICogRlJPTSBzaW1zIFdIRVJFIHppcCA9ICcwMDUwMSc7Cg==.

Does it check my SQL?

Only for one thing: a quoted string, quoted name, /* comment */ or PostgreSQL $$ body that is opened and never closed, which usually means the script was cut off. A note then names the line and column where it starts, and the text is still encoded exactly as typed. It does not run your queries or check table names, so any dialect works, from MySQL and PostgreSQL to SQL Server, SQLite and Oracle. To check the syntax itself, try the SQL Validator.

Is an uploaded .sql file encoded byte for byte?

Yes. An upload is read as raw bytes, so a byte-order mark, Windows line endings or a dump saved as Windows-1252 end up in the Base64 exactly as they are on disk. A file that isn't UTF-8 text isn't shown in the editor, but its bytes are still what you get. Text you type or paste is encoded as UTF-8.

Does Base64 hide passwords inside the script?

No. Base64 is an encoding, not encryption, and anyone holding the string can decode it in a second, for instance with the Base64 to SQL page. A Kubernetes Secret is only Base64 too, so if a script contains passwords or customer data, keep it in a real secret store or encrypt it. Base64 just makes the text safe to carry.

Where does my SQL go, and how large can a script be?

Nowhere. The encoding happens in your browser and the download file is built on your machine; nothing is uploaded and nothing is kept, so a reload starts with an empty editor. There is no fixed size cap. A dump of a few megabytes encodes in a moment, while very large files are limited by the memory your browser has. Expect the Base64 to be about a third longer than the SQL.

Related pages: Base64 to SQL · SQL Validator · SQL Formatter · Base64 Encoder