I am taking some columns values from a table and inserting it in another table. I am getting error at select count * statement. Error says"AttributeError: 'MySQLConnection' object has no attribute 'execute'". Below are the code:
import mysql.connector
print("after import")
#def takesubtable():
run = mysql.connector
connection = run.connect(host="localhost", user="user", password="password", database="db")
cursor = connection.cursor()
query1 = """CREATE TABLE IF NOT EXISTS Tablename
(column1 INT AUTO_INCREMENT PRIMARY KEY,
column2 DATE,
.
.
column10 varchar(45));"""
it = 1
cursor.execute(query1)
count = connection.execute("SELECT COUNT(*) FROM table")
#insert values from 1 table to another table
for i in count:
inssql = insert into table2(columns_list) values(%s, ......, %s)
val = select columns_list where column1 = {num}",it
op = cursor.execute(inssql,val)
it = it + 1
cursor.close()
connection.close()
Please help