gpt4 book ai didi

Python mysql 包未运行 REPLACE 语句

转载 作者:行者123 更新时间:2023-11-29 06:58:16 27 4
gpt4 key购买 nike

我遇到了一个问题,我有一个 SQL 语句,在我的 MySQL Workbench 中运行时可以正确执行,但是当使用 python 的 mysql 包函数 cursor.execute() 运行时则不起作用。有问题的SQL语句是:

REPLACE INTO mmm_dev.samp_wp_links SELECT * FROM mmm_master.samp_wp_links;

该语句应该将所有数据从 mmm_master 复制到 mmm_dev。以下是我用来执行查询的 python 代码:

cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
def examine(cursor, cnx):
try:
qry = cursor.execute("REPLACE INTO mmm_dev.samp_wp_links SELECT * FROM mmm_master.samp_wp_links;")
except mysql.connector.Error as err:
print("Failed to select everything")
exit(1)

最佳答案

MySQL Python 库是 PEP 249 - 符合:

.commit () Commit any pending transaction to the database.

Note that if the database supports an auto-commit feature, this must be initially off. An interface method may be provided to turn it back on.

Database modules that do not support transactions should implement this method with void functionality.

调用cnx.commit()

关于Python mysql 包未运行 REPLACE 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44728506/

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