gpt4 book ai didi

python - sqlalchemy,将 MySQL 字符集设置为 `create_engine` 参数

转载 作者:行者123 更新时间:2023-11-29 02:00:41 30 4
gpt4 key购买 nike

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

如果我像那样使用create_engine:

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

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

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.

根据 the documentation ,这种用法应该是可能的:

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

**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

最佳答案

额外的 DBAPI 参数,当单独传递时,通过 connect_args 传递.

关于python - sqlalchemy,将 MySQL 字符集设置为 `create_engine` 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15784357/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com