我是 python 的新手,我试图将数据从一个表插入到另一个表,代码正在执行,但它没有反射(reflect)我要插入数据的新表中的任何更改。
import mysql.connector
conn=mysql.connector.connect(user='root',password='',host='localhost',database='xyz')
mycursor=conn.cursor()
mycursor.execute("insert into newTable select * from oldTable group by mac,date,time order by mac")
最佳答案
我想这是因为您没有提交更改。使用下面的代码,看看它是否有效。
conn.commit()
您需要使用 conn,因为它是您连接到数据库的变量名。必须将提交发送到服务器,服务器将提交您的更改。
关于python - 如何将一张表中的数据插入到另一张表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54736162/