If I create a simple table in MySQL with binary data:
CREATE TABLE foo ( bar binary(4) )
INSERT INTO foo (bar) VALUES ( UNHEX('de12') )
Then try to read it using the MySQL Connector/Python:
import mysql.connector
conn = mysql.connector.connect(database='test', user='test')
cursor = conn.cursor()
cursor.execute("SELECT * FROM foo")
cursor.fetchall()
I get this error:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xde in position 0: invalid continuation byte
I don't understand why the Python MySQL connector is trying to decode the column as UTF-8. I just want to get the raw binary data, how can I do this?
(Python 2.7.10, Mysql 5.7.22, MySQL Connector/Python 8.0.12)