1.我通过python,向mysql插入类似b'\x33\x00\x78\xff'的数据。mysql的字段类型是varchar,插入之后发现,数据少了转义字符. 而且也不知道把数据重新读出来后,怎么把它从字符串变回字节类型的数据。
sql = "insert into myapp_userinfo (info) values (\"%s\")" % b'\x01\x00\x00\x00...'
xx.execute(sql)
...
2
varchar类型被我穿成blob,然后尝试继续插入,还是不行。
python读回来的结果
我希望数据能够原模原样的写进和读出来
刚接触python和mysql,这个问题弄了很久,有懂的人请回答下,谢谢!
伊谢尔伦2017-04-18 10:24:43
You can try to serialize the data and store it in the database, then transfer it once when you retrieve it. Try this
PHP中文网2017-04-18 10:24:43
It has something to do with the database encoding of the host. Just change all system encodings to utf-8
My database is encoded as follows:
黄舟2017-04-18 10:24:43
Mysql doesn’t have a data type specifically designed to store binary? BINARY and VARBINARY types
PHP中文网2017-04-18 10:24:43
You can consider encrypting the password into binary through AES and then base64_encode
转成字符串存储到密码字段中,读取时base64_decode
decoding it.