MySQL之以16进制读写
如果数据库使用gbk编码,列的编码是latin1,但实际是gbk,直接读取就会报错,这时可以直接读取二进制数据
读取
1 | SELECT hex(column1) FROM `my_table1`; |
1 | s = bytes.fromhex(column1_hex_data_str).decode('gbk') |
写入
1 | Update `table1` Set `column1` = unhex(%s) |
1 | column1_str = '我们' |
如果数据库使用gbk编码,列的编码是latin1,但实际是gbk,直接读取就会报错,这时可以直接读取二进制数据
1 | SELECT hex(column1) FROM `my_table1`; |
1 | s = bytes.fromhex(column1_hex_data_str).decode('gbk') |
1 | Update `table1` Set `column1` = unhex(%s) |
1 | column1_str = '我们' |