关于linux下python连接xp下的sql2005乱码问题

问题描述:
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值