MySQL 驱动程序与 INFORMATION_SCHEMA 存在问题?
我正在尝试 Stackless Python 的并发框架。它包含一个 MySQL 驱动程序,当运行一些之前在 MySQLdb 上运行良好的代码时,它会失败。
我正在做什么:
使用 dbapi 和用户名/密码/端口/数据库连接到 MySQL 数据库。
执行
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:
Connecting to the MySQL database using dbapi with username/password/port/database.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这绝对看起来像是驱动程序问题。也许 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 thenSELECT * FROM mydatabase.sometable
我终于找到原因了。
驱动程序只是在协议握手中回显服务器功能标志,但压缩除外:
由于服务器具有该功能...
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:
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.