关于linux下python连接xp下的sql2005乱码问题
2012-06-22 20:21
585 查看
问题描述:
1、A和B都是linux服务器上边都有python程序(一样的),都安装了pymssql、freetds
2、C是xp服务器上边运行sql2005
3、A、B两个服务器都通过如下命令执行:
>>> import pymssql
>>> connection = pymssql.connect(host="192.168.0.11",user="cc",password="cc",database="cc")
>>> cursor = connection.cursor()
>>> name='时间'
>>> age='23'
>>> sql ='''insert into testdb1(name,age) values('%s','%s')'''%(name,age)
>>> cursor.execute(sql)
>>> connection.commit()
问题:
在A服务器上运行插入的数据是正常的
但是,在B服务器运行插入的数据是乱码
问题补充:如下设置AB都一样:
[root@db-wanggaofei ~]# export LC_ALL=zh_CN.GBK
[root@localhost lsg]# locale
LANG=zh_CN.GBK
LC_CTYPE=zh_CN.UTF-8
LC_NUMERIC="zh_CN.GBK"
LC_TIME=zh_CN.UTF-8
LC_COLLATE="zh_CN.GBK"
LC_MONETARY="zh_CN.GBK"
LC_MESSAGES="zh_CN.GBK"
LC_PAPER="zh_CN.GBK"
LC_NAME="zh_CN.GBK"
LC_ADDRESS="zh_CN.GBK"
LC_TELEPHONE="zh_CN.GBK"
LC_MEASUREMENT="zh_CN.GBK"
LC_IDENTIFICATION="zh_CN.GBK"
LC_ALL=
[root@localhost lsg]# echo #lang
[root@localhost lsg]# echo #languge
i18n都追加:
LC_TIME="zh_CN.UTF-8"
LC_CTYPE="zh_CN.UTF-8"
LANG="zh_CN.UTF-8"
SYSFONT="latarcyrheb-sun16"
SUPPORTED="zh_CN.UTF-8:zh_CN:zh"
profile文件追加:
LC_ALL="zh_CN.GBK"
export LANG="zh_CN.GBK"
freetds.conf文件追加:
...............
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
client charset=utf8
或者client charset=gbk
或者client charset = GB2312
# A typical Sybase server
[egServer50]
.......................
出处:http://www.kcto.net/blog/detail.asp?id=44
1、A和B都是linux服务器上边都有python程序(一样的),都安装了pymssql、freetds
2、C是xp服务器上边运行sql2005
3、A、B两个服务器都通过如下命令执行:
>>> import pymssql
>>> connection = pymssql.connect(host="192.168.0.11",user="cc",password="cc",database="cc")
>>> cursor = connection.cursor()
>>> name='时间'
>>> age='23'
>>> sql ='''insert into testdb1(name,age) values('%s','%s')'''%(name,age)
>>> cursor.execute(sql)
>>> connection.commit()
问题:
在A服务器上运行插入的数据是正常的
但是,在B服务器运行插入的数据是乱码
问题补充:如下设置AB都一样:
[root@db-wanggaofei ~]# export LC_ALL=zh_CN.GBK
[root@localhost lsg]# locale
LANG=zh_CN.GBK
LC_CTYPE=zh_CN.UTF-8
LC_NUMERIC="zh_CN.GBK"
LC_TIME=zh_CN.UTF-8
LC_COLLATE="zh_CN.GBK"
LC_MONETARY="zh_CN.GBK"
LC_MESSAGES="zh_CN.GBK"
LC_PAPER="zh_CN.GBK"
LC_NAME="zh_CN.GBK"
LC_ADDRESS="zh_CN.GBK"
LC_TELEPHONE="zh_CN.GBK"
LC_MEASUREMENT="zh_CN.GBK"
LC_IDENTIFICATION="zh_CN.GBK"
LC_ALL=
[root@localhost lsg]# echo #lang
[root@localhost lsg]# echo #languge
i18n都追加:
LC_TIME="zh_CN.UTF-8"
LC_CTYPE="zh_CN.UTF-8"
LANG="zh_CN.UTF-8"
SYSFONT="latarcyrheb-sun16"
SUPPORTED="zh_CN.UTF-8:zh_CN:zh"
profile文件追加:
LC_ALL="zh_CN.GBK"
export LANG="zh_CN.GBK"
freetds.conf文件追加:
...............
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
client charset=utf8
或者client charset=gbk
或者client charset = GB2312
# A typical Sybase server
[egServer50]
.......................
出处:http://www.kcto.net/blog/detail.asp?id=44
相关文章推荐
- 关于Oracle for Linux sqlplus 的乱码问题
- 关于python连接mysql中文乱码问题
- 关于在xp系统上sql2005创建用户失败的问题
- 关于Linux连接工具mobaxterm显示中文乱码问题
- 关于在java中连接MS SQL Server 2005 JDBC的问题及解决办法
- 关于Oracle for Linux sqlplus 的乱码问题
- 关于Linux连接工具mobaxterm显示中文乱码问题(二)
- 关于在java中连接MS SQL Server 2005 JDBC的问题及解决办法
- ssh 连接linux中文乱码问题,解决
- 关于LINUX系统netterm终端登陆乱码问题。
- 关于linux下python的升级和安装软件时遇到对python2.4的依赖问题
- 关于Centos Linux系统安装Python的问题
- PL/SQL中关于显示中文乱码问题
- SecureCRT连接Linux,终端显示中文乱码问题,全方面解决
- linux下Python各种关于路径问题的解决办法
- 【python】解决linux下unzip乱码问题
- 【SQL Server 2005 的问题】com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。该用户与可信 SQL Server 连接无关联。
- LINUX下php连接mssql数据库中文字符乱码问题解决
- 关于sql 2005 express 远程访问和sa密码的问题(转帖)
- SSH无法连接VMware内Linux及中文乱码问题