MySQL 驱动程序与 INFORMATION_SCHEMA 存在问题?

发布于 2024-08-13 05:43:42 字数 880 浏览 9 评论 0原文

我正在尝试 Stackless Python 的并发框架。它包含一个 MySQL 驱动程序,当运行一些之前在 MySQLdb 上运行良好的代码时,它会失败。

我正在做什么:

  1. 使用 dbapi 和用户名/密码/端口/数据库连接到 MySQL 数据库。

  2. 执行 SELECT * FROM INFORMATION_SCHEMA.COLUMNS

失败并显示消息:

Table 'mydatabase.columns' doesn't exist

“mydatabase”是我在步骤中指定的数据库1.

在发出“USE mydatabase”后在MySQL控制台中执行相同的查询时,它工作得很好。

检查网络通信会产生如下结果:

>>>myusername
>>>scrambled password
>>>mydatabase

>>>CMD 3 SET AUTOCOMMIT = 0
<<<0

>>>CMD 3 SELECT * FROM INFORMATION_SCHEMA.COLUMNS
<<<255
<<<Table 'mydatabase.columns' doesn't exist

这是驱动程序问题吗(因为它在 MySQLdb 中工作)?或者我不应该能够以这种方式查询 INFORMATION_SCHEMA 吗?

如果我在尝试查询之前发送特定的“USE INFORMATION_SCHEMA”,我会得到预期的结果。但是,我不想让我的代码到处都是“USE”查询。

I'm trying out the Concurrence framework for Stackless Python. It includes a MySQL driver and when running some code that previously ran fine with MySQLdb it fails.

What I am doing:

  1. Connecting to the MySQL database using dbapi with username/password/port/database.

  2. Executing SELECT * FROM INFORMATION_SCHEMA.COLUMNS

This fails with message:

Table 'mydatabase.columns' doesn't exist

"mydatabase" is the database I specified in step 1.

When doing the same query in the MySQL console after issuing "USE mydatabase", it works perfectly.

Checking the network communication yields something like this:

>>>myusername
>>>scrambled password
>>>mydatabase

>>>CMD 3 SET AUTOCOMMIT = 0
<<<0

>>>CMD 3 SELECT * FROM INFORMATION_SCHEMA.COLUMNS
<<<255
<<<Table 'mydatabase.columns' doesn't exist

Is this a driver issue (since it works in MySQLdb)? Or am I not supposed to be able to query INFORMATION_SCHEMA this way?

If I send a specific "USE INFORMATION_SCHEMA" before trying to query it, I get the expected result. But, I do not want to have to sprinkle my code all over with "USE" queries.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沐歌 2024-08-20 05:43:42

这绝对看起来像是驱动程序问题。也许 python 驱动程序不支持 DB 前缀。

为了确定起见,请尝试相反的方法:首先使用 INFORMATION_SCHEMA,然后SELECT * FROM mydatabase.sometable

It definitely looks like a driver issue. Maybe the python driver don't support the DB prefix.

Just to be sure, try the other way around: first use INFORMATION_SCHEMA and then SELECT * FROM mydatabase.sometable

茶花眉 2024-08-20 05:43:42

我终于找到原因了。

驱动程序只是在协议握手中回显服务器功能标志,但压缩除外:

## concurrence/database/mysql/client.py ##

client_caps = server_caps 

#always turn off compression
client_caps &= ~CAPS.COMPRESS

由于服务器具有该功能...

CLIENT_NO_SCHEMA 16 /* 不允许database.table.column */

...这被回显到服务器,告诉它不允许该语法。

添加 client_caps &= ~CAPS.NO_SCHEMA 就成功了。

I finally found the reason.

The driver just echoed the server capability flags back in the protocol handshake, with the exception of compression:

## concurrence/database/mysql/client.py ##

client_caps = server_caps 

#always turn off compression
client_caps &= ~CAPS.COMPRESS

As the server has the capability...

CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */

...that was echoed back to the server, telling it not to allow that syntax.

Adding client_caps &= ~CAPS.NO_SCHEMA did the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文