title: Convert jpg images to blob and store it in a .sql file
body: <p>I store jpg images into a mysql database.</p>
  
  <p>I use the BLOB type to store the jpg images in the mysql database.</p>
  
  <p>I use mysqldump to generate a .sql file.</p>
  
  <p>I use the .sql file as backup and restore the database.</p>
  
  <p>How can I convert a jpg directly to a .sql file?</p>
  
  <p>I have tried this python code:</p>
  
  <pre><code>import os
  
  import base64
  
  archivo_destino = ".\\portada_sql\\archivo.sql"
  
  imagen_origen = ".\\libros_nuevos_jpg\\03000\\000.jpg"
  
  archivo = open(archivo_destino, 'w')
  
  imageFile = open(imagen_origen, "rb") 
  
  mi_blob = base64.b64encode(imageFile.read())
  
  archivo.write("INSERT INTO libro_portada VALUES ('"+mi_blob+"');")
  
  archivo.close()
  </code></pre>
  
  <p>But it does not work.</p>
  
  <p>It is possible to create a sql file with a image stored as blob usign python?</p>
  
  <p>I try to avoid:</p>
  
  <ul>
  <li>upload the jpg to the server</li>
  <li>import jpg to mysql</li>
  <li>export mysql to .sql file</li>
  </ul>
  
  <p>I want to generate directly the .sql file.</p>
  
  <p>It is possible?</p>
  
  <p>1.
  Magnus:
  I mentioned php  because I can use php too, if this is possible with php.</p>
  
  <p>2.
  Eric:
  From the python code mentioned above, I get:</p>
  
  <p>INSERT INTO libro_portada VALUES ('b'/9j/4RivRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAE'');</p>
  
  <p>From mysqldump I get:</p>
  
  <p>INSERT INTO <code>libro_portada</code> VALUES ('ÿ\؀ÿ\ကJExif\0\0MM\0*\0\0\0\0\0\0\0\0\0\0\0\Z\0\0\0\0\0\0\0b');</p>