在Python和MySQL
To address this issue, you have two options:
Modifying the Database Table:
You can modify the database table to use a Unicode-friendly character set.更改varbinary列以使用诸如utf8mb4或utf8 general_ci的类型。
在python中的处理编码:
确保负责读取和插入数据的Python代码也使用UTF-8编码。在字符串上使用.encode('utf-8')方法将它们转换为UTF-8,然后将它们插入数据库。- 这是一个更新的python代码段,该python代码段包含了charset参数:
cur.execute(“设置名称utf8”)
cur.execute(“插入yahoo_questions(Question_ID,Question_subj,Question_content,Question_userid,Question_timestamp,”,“
“ category_id,category_name,chososy_answer,choposen_userid,choposen_usernick,chososy_ans_timestamp)”
“值(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)”,
(行[2],行[5] .encode('utf-8'),行[6] .encode('utf-8'),quserid,Quesserid,Questiontime,
categoryId,categoryName,qchosenanswer.encode('utf-8'),chosecomEserid,choosennickname,choosentimestamp))
确保您的数据库变量也正确设置了。 targin_set_database变量应设置为UTF8以匹配表和连接设置。