MySQL 'SHOW TABLES' Returns 计数而不是列表 (Python)
MySQL 'SHOW TABLES' Returns count instead of list (Python)
我正在对用于查询数据库的脚本进行故障排除。为了确保一切正常,我将其简化为一个简单的 'SHOW TABLES' 查询。问题是它 return 计算表的数量而不是它应该 return 的名称列表。
import pymysql
connection = pymysql.connect(host='10.0.0.208', user='admin', passwd='Passwrd')
cursor = connection.cursor()
sqlstring = 'SHOW TABLES;'
cursor.execute('USE CustDB')
x = cursor.execute(sqlstring)
print(x)
这只是 return'17'。我错过了什么??
根据 documentation、execute
returns 受影响的行数
Returns: Number of affected rows
为了得到想要的结果,你需要遍历 cursor
cursor.execute('USE CustDB')
tables = [c for c in cursor]
或使用fetchall
cursor.execute('USE CustDB')
tables = cursor.fetchall()
我正在对用于查询数据库的脚本进行故障排除。为了确保一切正常,我将其简化为一个简单的 'SHOW TABLES' 查询。问题是它 return 计算表的数量而不是它应该 return 的名称列表。
import pymysql
connection = pymysql.connect(host='10.0.0.208', user='admin', passwd='Passwrd')
cursor = connection.cursor()
sqlstring = 'SHOW TABLES;'
cursor.execute('USE CustDB')
x = cursor.execute(sqlstring)
print(x)
这只是 return'17'。我错过了什么??
根据 documentation、execute
returns 受影响的行数
Returns: Number of affected rows
为了得到想要的结果,你需要遍历 cursor
cursor.execute('USE CustDB')
tables = [c for c in cursor]
或使用fetchall
cursor.execute('USE CustDB')
tables = cursor.fetchall()