[英]How to insert data from one table into another table?
I'm new to python and I was trying to insert data from one table to another and the code is executing but it is not reflecting any changes in new table in which I want to insert data. 我是python的新手,我试图将数据从一个表插入到另一个表中,并且代码正在执行,但是它没有反映我要在其中插入数据的新表中的任何更改。
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")
您需要添加commit()进行更改。
conn.commit()
I suppose it is because you are not committing the changes. 我想这是因为您没有提交更改。 Use the below code and see if it works.
使用下面的代码,看看它是否有效。
conn.commit()
You need to use conn because that is the variable name for your connection to the database. 您需要使用conn,因为那是您与数据库连接的变量名。 A commit must be sent to the server, which in turn will commit your changes.
必须将提交发送到服务器,然后服务器将提交您的更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.