Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

saving blob field to disk from bash

Tags:

bash

mysql

I have a mysql database with a blob field containing a zip and I need to save it as a file on disk, from bash. I'm doing the following but the end result doesn't read as a zip... Am I doing something wrong or is the file stored not actually a zip (the entry in the database is actually created by a seismological station, so I have no control over it)?

echo "USE database; SELECT blobcolumn FROM table LIMIT 1" | mysql -u root > file.zip

then I open file.zip with a file editor and remove first line which contains the column header. Then 'unzip' doesn't recognize it as a zip file.

like image 665
nareto Avatar asked May 10 '26 16:05

nareto


1 Answers

For a gzipped blob you can use:

echo "use db; select blob from table where id=blah" | mysql -N --raw -uuser -ppass > mysql.gz

I have not tried this with a zip file.

like image 62
sumo Avatar answered May 12 '26 08:05

sumo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!