title: Inserting and retrieving images into mysql through python
body: <p>I used this code to insert an image into mysql database and retrieve back the image.
  This code works perfectly with no errors , but the problem is even after inserting an image into img table , when I execute the command <code>select  * from img ;</code> in the mysql command line it shows no records.</p>
  <p>Table created in database;</p>
  <pre class="lang-sql prettyprint-override"><code>create table img(images blob not null);
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>import mysql.connector
  import sys
  from PIL import Image
  import base64
  import cStringIO
  import PIL.Image
  
  db = mysql.connector.connect(user='root', password='abhi',
                                host='localhost',
                                database='cbir')
  
  #image = Image.open('C:\Users\Abhi\Desktop\cbir-p\images.jpg')
  with open(&quot;C:\Users\Abhi\Desktop\cbir-p\images.jpg&quot;, &quot;rb&quot;) as image_file:
      encoded_string = base64.b64encode(image_file.read())
  
  #blob_value = open('C:\Users\Abhi\Desktop\cbir-p\images.jpg', 'rb').read()
  sql = 'INSERT INTO img(images) VALUES(%s)'    
  args = (encoded_string, )
  cursor=db.cursor()
  cursor.execute(sql,args)
  sql1='select * from img'
  cursor.execute(sql1)
  data=cursor.fetchall()
  #print type(data[0][0])
  data1=base64.b64decode(data[0][0])
  file_like=cStringIO.StringIO(data1)
  img=PIL.Image.open(file_like)
  img.show()
  
  db.close()
  </code></pre>