简体   繁体   中英

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.

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. A commit must be sent to the server, which in turn will commit your changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM