gpt4 book ai didi

mysql - 如何使用Explain命令使用Python连接Mysql?

转载 作者:行者123 更新时间:2023-11-29 15:49:58 25 4
gpt4 key购买 nike

解释方法/命令似乎不适用于 python mysql 连接。其他查询显示正确的结果,但使用解释命令则不显示任何内容。代码打印和注释是葡萄牙语的。我正在使用 DataFrames 来显示查询结果的内容以显示问题/错误/其他。代码是缩进的,因为它刚刚从 Visual Studio 中出来。我用谷歌搜索了很多,但没有找到任何线索。

            print("#########################################################################################")
# ANTES DE EXECUTAR CADA UMA DAS QUERYS VEREFICAR QUAIS AS TABELAS QUE SAO UTLIZADAS EM CADA UMA
# VERIFICAR QUE TABELAS EXISTEM PARA O PROFESSOR
query = "EXPLAIN " + sqlqueryprof
print("QUERY EXPLAIN DO PROFESSOR")
print(query)
#connection.commit()
cursor = connection.cursor()
cursor.execute(query)
explain_prof = cur.fetchall()
print("TABELA EXPLICATIVA DA QUERY DO PROFESSOR")
data_frame_expl_prof = pandas.DataFrame(list(explain_prof))
print(data_frame_expl_prof)

# VERIFICAR QUE TABELAS EXISTEM PARA O ALUNO
query = "EXPLAIN " + sqlqueryalun
print("QUERY EXPLAIN DO ALUNO")
print(query)
#connection.commit()
cursor = connection.cursor()
cursor.execute(query)
explain_alun = cur.fetchall()
print("TABELA EXPLICATIVA DA QUERY DO ALUNO")
data_frame_expl_alun = pandas.DataFrame(list(explain_alun))
print(data_frame_expl_alun)

print("#################################################################")
# EXECUTAR CADA UMA DAS QUERYS
cursor_prof = connection.cursor()
cursor_prof.execute(sqlqueryprof)
records_prof = cursor_prof.fetchall()

data_frame_prof = pandas.DataFrame(list(records_prof))
print("IMPRIMIR O DATA FRAME RESULTANTE DO PROFESSOR A CONEXAO")
print(data_frame_prof)

cursor_alun = connection.cursor()
cursor_alun.execute(sqlqueryalun)
records_query = cursor_alun.fetchall()

data_frame_alun = pandas.DataFrame(list(records_query))
print("IMPRIMIR O DATA FRAME RESULTANTE DO ALUNO A CONEXAO")
print(data_frame_alun)

enter image description here

最佳答案

是否是因为您使用了 cur.fetchall() 而不是 cursor.fetchall()

[...]
cursor = connection.cursor()
cursor.execute(query)
explain_prof = cursor.fetchall()
[...]

关于mysql - 如何使用Explain命令使用Python连接Mysql?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56817409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com