python脚本导入mysql中文乱码
2016-01-12 11:46
591 查看
实际工作中经常会涉及到脚本导入数据到库中, 如果数据中有中文,搞不好会出现乱码问题。根据实际工作中的经验,为了避免乱码,总结了如下经验:
以数据库编码为utf-8为例
1、把导入文件修改成utf-8编码
ue: 文件-转换-asc到utf8
2、脚本连接数据库使用utf-8编码
MySQLdb.connect(host=hostname, user=username, passwd=password, db=dbname,
charset='utf8', use_unicode=True)
以上两个步骤基本可以解决中文乱码问题
以数据库编码为utf-8为例
1、把导入文件修改成utf-8编码
ue: 文件-转换-asc到utf8
2、脚本连接数据库使用utf-8编码
MySQLdb.connect(host=hostname, user=username, passwd=password, db=dbname,
charset='utf8', use_unicode=True)
以上两个步骤基本可以解决中文乱码问题
相关文章推荐
- 28. Implement strStr() leetcode Python new season 2016
- WIN10 64bit python3.4 安装 numpy scipy matplotlib
- python代码段
- 27. Remove Element leetcode python 2016 new season
- Python 连接 MySQL数据库
- python数字图像处理(6):图像的批量处理
- python操作MySQL数据库
- python遍历文件夹并实现分级缩进显示
- Python -- str 类
- python中if __name__ == '__main__': 的解析
- python生成随机数组
- Python异常处理
- Python中的method
- Python下划线与命名规范
- Python开发Webservice(SOAP)
- WIN10 64bit python2.7 安装 numpy scipy matplotlib
- 【极客学院】-python学习笔记-3-单线程爬虫 (request安装遇到问题及解决,应用requests提取信息)
- Python系列之 - Collections系列
- 从0到1 python简易计算器
- Cairo Tutorial for Python Programmers