Python mysql 包未运行 REPLACE 语句

标签 python mysql wordpress

我遇到了一个问题,我有一个 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/

相关文章:

php - Laravel 数据透视表中的一对多关系?

mysql - WordPress:加入用户、元和外部表问题

Python 替换 Dataframe 字符串中的整个值而不是子字符串

python - 因瓶颈错误而无法构建轮子

python - 无法使用 django 框架连接 mysql 数据库

wordpress - 如何使 gzip 在 1and1 共​​享主机 WordPress 网站上工作

css - Google 字体根本没有导入到我的样式表中

python - 如何在 python 中为 xticklabels 添加空间?

python - REST 响应内容 "magically"如何从 'list' 转换为 'string'

php - 导出 CSV |奇怪的行为