xcv*_*vbn 2 python mysql utf-8 iso-8859-1 character-encoding
我试图使用MySQLdb驱动程序将一些阿拉伯语单词插入arabic_word我的hanswehr2数据库Maria DB 的列中.
我得到了一个latin-1 encode error.但在阅读之后,我发现MySQLdb驱动程序是默认的latin-1,我必须在函数中明确设置utf-8为我的选择字符集mariadb.connect().酱.
整个数据库设置为utf-8.
码:
def insert_into_db(arabic_word, definition):
try:
conn = mariadb.connect('localhost', 'root', 'xyz1234passwd', 'hans_wehr', charset='utf-8', use_unicode=True)
conn.autocommit(True)
cur = conn.cursor()
cur.execute("INSERT INTO hanswehr2 (arabic_word , definition) VALUES (%s,%s)", (arabic_word, definition,))
except mariadb.Error, e:
print e
sys.exit(1)
Run Code Online (Sandbox Code Playgroud)
但是现在我收到以下错误:
/usr/bin/python2.7 /home/heisenberg/hans_wehr/main.py
Total lines 87672
(2019, "Can't initialize character set utf-8 (path: /usr/share/mysql/charsets/)")
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
我已经指定Python MySQL驱动程序使用utf-8字符,但它似乎忽略了这一点.
任何投入都将受到高度赞赏.
MySQL中UTF-8的charset别名是utf8(无连字符).
有关可用的字符集,请参阅https://dev.mysql.com/doc/refman/5.5/en/charset-charsets.html.
注意,如果需要使用非BMP Unicode点,例如emojis,请使用utf8mb4连接字符集和varchar类型.
| 归档时间: |
|
| 查看次数: |
4944 次 |
| 最近记录: |