您的位置:首页 > 运维架构 > Linux

关于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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: