Reputation: 105
HI all i am trying to delete the contents of my tabel before entering new data and i cant seem to get it to work , i keep on getting a error or is there a better way then i am trying to do it, here is the code thank you all for your help in advance
import mysql.connector
import pandas as pd
import mysql.connector
from mysql.connector import Error
print ("Clearning Flight Data table for new data")
try:
connection = mysql.connector.connect(host='localhost',
database='flightdata',
user='root',
password='*****')
cursor = connection.cursor()
Delete_all_rows = """flightinfo """
cursor.execute(Delete_all_rows)
connection.commit()
print("All Record Deleted successfully ")
except mysql.connector.Error as error:
print("Failed to Delete all records from database table: {}".format(error))
finally:
if (connection.is_connected()):
cursor.close()
connection.close()
print("MySQL connection is closed")
print ("Running Sydney KWS Domestic update")
import syd_kws_dom
print ("Running Sydney KWS International update")
import syd_kws_int
Upvotes: 0
Views: 383
Reputation: 3519
delete
query using cursor.execute
.Delete_all_rows = """delete from flightinfo """
cursor.execute(Delete_all_rows)
Upvotes: 1