MySQL Python模块中的cursor.fetchall()
我想练习在python脚本中使用MySQL查询的技巧。 首先,我正在使用脚本,它将能够从我的MySQL Python模块中的cursor.fetchall(),python,sql,ubuntu,Python,Sql,Ubuntu,我想练习在python脚本中使用MySQL查询的技巧。 首先,我正在使用脚本,它将能够从我的sql服务器(我使用的是ubuntu)获取所有数据库 我写了这样一篇文章: #!/usr/bin/env python # -*- coding: utf-8 -*- import MySQLdb as mdb import sys try: con = mdb.connect('localhost', 'testuser', 'testuser', 'test') cursor =
sql
服务器(我使用的是ubuntu)获取所有数据库
我写了这样一篇文章:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb as mdb
import sys
try:
con = mdb.connect('localhost', 'testuser', 'testuser', 'test')
cursor = con.cursor()
cursor.execute("SHOW DATABASES;")
for row in cursor:
print row
except mdb.Error, e:
print "Errot %d: %s" % (e.args[0], e.args[1])
sys.exit(1)
finally:
if con:
con.close()
它返回:
('information_schema',)
('test',)
While I have more that that 2 databases - Output from mysql console is:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| test1 |
+--------------------+
你能告诉我我做错了什么吗?你在控制台上使用的用户和在Python脚本上使用的是同一个用户吗?(即用户名:testuser密码:testuser)谢谢:D这是一个愚蠢的错误,现在可以正常工作了:)