Reputation: 11
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.
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")
Upvotes: 1
Views: 1725
Reputation: 75
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. A commit must be sent to the server, which in turn will commit your changes.
Upvotes: 1