Python往MySQL存储图片
来源:互联网 发布:linux free m 详解 编辑:程序博客网 时间:2024/06/07 05:37
Python往MySQL存储图片
新建表img,设置id字段和imgs字段(设置为blob属性,二进制数据)
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2017/8/18 11:37# @File : Picture.pyimport MySQLdb as mysqlimport sysconn=mysql.connect(host='localhost',user='root',passwd='xxx',db='mydata')fp = open("./1.jpg")img = fp.read()fp.close()#存入图片def insert_imgs(img): # mysql连接 cursor = conn.cursor() # 注意使用Binary()函数来指定存储的是二进制 # cursor.execute("insert into img set imgs='%s'" % mysql.Binary(img)) cursor.execute("Insert into img(imgs) values(%s)", (mysql.Binary(img))) # 如果数据库没有设置自动提交,这里要提交一下 conn.commit() cursor.close() # 关闭数据库连接 conn.close()#提取图片def select_imgs(img): cursor=conn.cursor() cursor.execute('select imgs from img') print cursor.fetchall() cursor.close() conn.close()
阅读全文
0 0
- Python往MySQL存储图片
- mysql 图片存储到数据库中 python
- python 向mysql中存储图片以及读取图片
- 往MySQL中存储图片
- 往MySQL中存储图片
- 往MySQL中存储图片
- 往MySQL中存储图片
- 往MySQL中存储图片
- 往MySQL中存储图片
- 往MySQL中存储图片
- python爬取微博图片数据存到Mysql中遇到的各种坑\python Mysql存储图片\python爬取微博图片
- 往MySQL中存储图片 longBlob类型
- MySQL如何存储图片
- python 存储bmp格式图片
- Java操作mysql存储图片
- PHP、MySQL存储显示图片
- mysql存储和读取图片
- 数据库Mysql存储,读取图片
- BGP2
- httpd 2.4.25 php5.6.30…
- BGP2
- 帆软报表通过FR.showDialog打开对话框
- ubuntu httpd 开启 server-status
- Python往MySQL存储图片
- apache 2.4.25 关闭列出目录
- 第3章数据和C
- H3C路由器配置
- MyBatis框架环境搭建以及配置
- ubuntu停止httpd服务
- 项目中遇到的单词.句子.积累
- apahce2.2 http https ssl/tls 加…
- ios andior pc使用数据库的存储路径