擅长:python、mysql、java
<p>当你使用二进制排序规则时,似乎会发生这种情况,至少在我身上也是如此。要将bytearray转换为Unicode字符串,可以添加自定义转换器类:</p>
<pre><code>class MyConverter(mysql.connector.conversion.MySQLConverter):
def row_to_python(self, row, fields):
row = super(MyConverter, self).row_to_python(row, fields)
def to_unicode(col):
if isinstance(col, bytearray):
return col.decode('utf-8')
return col
return[to_unicode(col) for col in row]
sql = mysql.connector.connect(converter_class=MyConverter, host=...)
</code></pre>