Storing a EXE inside MySQL

It’s possible to store a EXE file inside a MySQL database. You can try this out. For demonstration purposes I’m running MySQL in my localhost. I will be creating a simple database and a table big enough to store the exe file. Since we convert the exe to a hex file the content would be larger than the original exe file. I will be using ‘putty.exe’ as the binary.


USE testupload

CREATE TABLE uploads (
 name VARCHAR(1000000) NOT NULL,

First we convert the exe in hex format. For this we can use MySQL’s hex() function.

select hex(load_file('C:/tmp/putty.exe')) into dumpfile 'C:/tmp/putty.dmp';

Next let’s store the dumped hex file inside our table.

load data infile 'C:/tmp/putty.dmp' into table uploads fields 
terminated by '@OsandaMalith' lines terminated by '@OsandaMalith' (name);

Now we can dump the file from our table and see nothing has changed. We use the unhex() function in MySQL to convert back to a exe.

select unhex(name) from uploads into dumpfile 'C:/tmp/new.exe';

Let’s check the SHA-256 checksum of both the original and the new exe file and you can see no change has been occurred during this process.

One thought on “Storing a EXE inside MySQL

Leave a Reply to akamajoris Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.