sqlalchemy,将MySQL字符集设置为`create_engine`参数 [英] sqlalchemy, setting MySQL charset as `create_engine` argument

查看:726
本文介绍了sqlalchemy,将MySQL字符集设置为`create_engine`参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建连接到MySQL数据库的sqlalchemy引擎.我想将charset指定为 create_engine 参数.

I create sqlalchemy engine connecting to MySQL database. I want to specify charset as create_engine argument.

如果我使用create_engine的话,

create_engine('mysql+mysqldb://pd:pd@localhost/pd?charset=utf8') 

那一切都很好.但是,当我这样使用它时:

then all is fine. But, when I use it like that:

create_engine('mysql+mysqldb://pd:pd@localhost/pd', charset='utf8') 

然后出现以下错误:

TypeError: Invalid argument(s) 'charset' sent to create_engine(), using
    configuration MySQLDialect_mysqldb/QueuePool/Engine. Please check that
    the keyword arguments are appropriate for this combination of components.

根据文档,此用法应该是可能的:

According to the documentation, this usage should be possible:

URL的字符串形式为 Dialect + driver://user:password @ host/dbname [?key = value ..] ...

The string form of the URL is dialect+driver://user:password@host/dbname[?key=value..] ...

** kwargs采取了各种各样的选择,这些选择都指向其适当的组件.参数可能是特定于引擎的, 基础方言以及池.特定的方言也 接受该方言独有的关键字参数.在这里,我们 描述大多数create_engine()用法通用的参数.

**kwargs takes a wide variety of options which are routed towards their appropriate components. Arguments may be specific to the Engine, the underlying Dialect, as well as the Pool. Specific dialects also accept keyword arguments that are unique to that dialect. Here, we describe the parameters that are common to most create_engine() usage.

为什么我不能分别指定charset?

Why I cannot specify charset separately?

推荐答案

其他DBAPI参数(分别传递)通过

the additional DBAPI arguments, when passed separately, are passed via connect_args.

这篇关于sqlalchemy,将MySQL字符集设置为`create_engine`参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆