gpt4 book ai didi

mysql - Sqlalchemy 无法连接到 mysql 服务器

转载 作者:行者123 更新时间:2023-11-29 14:53:42 25 4
gpt4 key购买 nike

我的旧版 mysql 4.0.20 服务器位于 Windows 计算机上。我正在 Linux 上开发一个新系统(基于 python),需要连接到旧服务器并进行查询等。我已经使用普通 MySQLdb 和 django 成功连接。我在使用 sqlalchemy 连接时遇到问题。这是代码:

conn_str = "mysql://user:pass@192.168.171.233/dbd"
engine = create_engine(conn_str, echo=True)
metadata = MetaData(engine)
connection = engine.connect()

以及我收到的错误堆栈:

2011-03-01 08:35:04,613 INFO sqlalchemy.engine.base.Engine.0x...b42c SELECT DATABASE() 2011-03-01 08:35:04,613 INFO sqlalchemy.engine.base.Engine.0x...b42c () Traceback (most recent call last):

connection = engine.connect() File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/engine/base.py", line 1811, in connect return self.Connection(self, **kwargs) File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/engine/base.py", line 832, in init self.connection = connection or engine.raw_connection() File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/engine/base.py", line 1874, in raw_connection return self.pool.unique_connection() File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/pool.py", line 142, in unique_connection return _ConnectionFairy(self).checkout() File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/pool.py", line 369, in __init rec = self._connection_record = pool.get() File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/pool.py", line 213, in get return self.do_get() File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/pool.py", line 732, in do_get con = self.create_connection() File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/pool.py", line 147, in create_connection return _ConnectionRecord(self) File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/pool.py", line 258, in init l.first_connect(self.connection, self) File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/engine/strategies.py", line 151, in first_connect dialect.initialize(c) File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/dialects/mysql/base.py", line 1753, in initialize default.DefaultDialect.initialize(self, connection) File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/engine/default.py", line 159, in initialize self.returns_unicode_strings = self._check_unicode_returns(connection) File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/engine/default.py", line 205, in _check_unicode_returns unicode_for_varchar = check_unicode(sqltypes.VARCHAR(60)) File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/engine/default.py", line 195, in check_unicode ]).compile(dialect=self) File "/usr/local/lib/python2.6/dist-packages/MySQL_python-1.2.3c1-py2.6-linux-i686.egg/MySQLdb/cursors.py", line 173, in execute self.errorhandler(self, exc, value) File "/usr/local/lib/python2.6/dist-packages/MySQL_python-1.2.3c1-py2.6-linux-i686.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue ProgrammingError: (1064, "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(60)) AS anon_1' at line 1")

最佳答案

看起来 MySQL 正在报告您的 SQL 语句之一中的语法错误:

<截图>

1064, "You have an error in your SQL syntax.
Check the manual that corresponds to your MySQL server
version for the right syntax to use near
'(60)) AS anon_1' at line 1

看起来 MySQL 正在反对包含以下字符串的语句:

(60)) AS anon_1

注意:我不熟悉 Sqlalchemy,但在我看来,异常(语句中的 SQL 错误)正在传播到连接中指定的处理程序。

FOLLOWUP:Sqlalchemy 正在执行的查询可能与旧版本的 MySQL 不兼容。看起来它在“_check_unicode_returns”函数中。

您是否尝试过禁用 unicode 支持?

conn_str = "mysql://user:pass@192.168.171.233/dbd?use_unicode=0"

关于mysql - Sqlalchemy 无法连接到 mysql 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5156915/

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