linux expect 字符集,无法将字符集结果设置为latin1

我决定在python3中首次使用django1.7。

我需要能够使用包含utf8数据的遗留latin1数据库。我知道这很糟糕,但是数据库太大了,根本不可能改变这一点。所以我试着:DATABASES = {

'ENGINE' : 'django.db.backends.mysql', // using MySQL-python fork with support for py3

...

'OPTIONS' : {

'init_command': "SET character_set_results = 'latin1'",

#'read_default_file': '/etc/my.cnf.d/client.cnf', // I've also tried this one

}

}

我还尝试了Oracle中的pythonmysql连接器,其设置如下

^{pr2}$

/等/我的.cnf.d/客户端.cnf在[client]

init-command='SET character_set_results = "latin1"'

# password, host, username

在这两种情况下,我都可以连接到数据库,但看起来Django将character_set_results设置回utf8。在

我试着跟着from django.db import connection

with connection.cursor() as c:

// I expect variable to be 'latin1'

c.execute("show variables like 'character_set_results%'")

c.fetchone() // returns ('character_set_results', 'utf8')

// here I try to set it manually

c.execute("SET character_set_results = 'latin1'")

c.execute("show variables like 'character_set_results%'")

c.fetchone() // returns ('character_set_results', 'latin1') // now it's OK我确信django使用了client.cfg文件并更正了[section],因为它包含用户名/密码,并且成功地连接到数据库

当我在使用相同配置文件的linux终端中使用mysql命令时,一切正常

所以我猜Django以某种方式强制character_set_results变量为utf8。有可能吗?我有什么办法可以解决这个问题吗?在

非常感谢

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值