我想练习在python脚本中使用MySQL查询的技巧。
首先,我正在使用script,它可以从我的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 |
+--------------------+
你能告诉我我做错了什么吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐