How to read a binary file into a mysql table
Hans Müller
HeinTest at web.de
Fri Dec 14 10:19:41 EST 2007
Good morning folks,
I cannot read a binary file into a mysql database. Everything I tried did not succeed.
What I tried (found from various google lookups...) is this:
con = MySQLdb.connect(to server)
cur = con.cursor()
cur.execute("insert into data values('file1', %s)", (open("test.jpg", "rb").read(), ))
also this doesn't work:
execute("insert into data values('file1', %s), (MySQLdb.escape_string(open("test.jpg", "rb").read()), ))
I always get this:
Warning: Data truncated for column 'file' at row 1
The blob data is actually chopped.
The Table has two columns, char(100), blob
Has someone a working idea how to get binary file into a blob using MySQLdb and python ?!
System is SuSE 10.0 Linux with python 2.5.1, current MySQLdb version, MySQL is: 5.0.26
Thanks a lot!
Greetings
Hans
More information about the Python-list
mailing list