1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > mysql数据库西里尔文乱码_使用Python从MySQL读取西里尔文utf8符号不正确

mysql数据库西里尔文乱码_使用Python从MySQL读取西里尔文utf8符号不正确

时间:2018-11-28 18:32:28

相关推荐

mysql数据库西里尔文乱码_使用Python从MySQL读取西里尔文utf8符号不正确

下面是我的代码,它连接到数据库,并将俄语单词插入数据库:import mysql.connector

if __name__ == '__main__':

try:

cnx = mysql.connector.connect(user='user', password='password',

host='123.123.123.123',

database='db_name',

charset='utf8',

collation='utf8_general_ci',

use_unicode=True)

except BaseException as ex:

print('Error: ' + str(ex))

cnx.close()

else:

print('Connections succesful!')

cnx.set_charset_collation('utf8', 'utf8_general_ci')

cursor = cnx.cursor()

print(cnx.charset)

cursor.execute("INSERT INTO table_name (column_name) values ('привет!')") #means 'Hello!' in russian

cursor.execute("SELECT * FROM test_referers")

print(cursor.fetchall())

我得到的是:

^{pr2}$

这样的输出同时出现在Python解释器控制台和eclipsepydev中。在

请帮忙

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。