first_project
This commit is contained in:
36
truncate_table.py
Normal file
36
truncate_table.py
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
import mysql.connector
|
||||
|
||||
def get_connection_details():
|
||||
details = {}
|
||||
with open('setting.txt', 'r') as f:
|
||||
for line in f:
|
||||
key, value = line.strip().split(':', 1)
|
||||
details[key.strip()] = value.strip()
|
||||
return details
|
||||
|
||||
def truncate_table():
|
||||
conn = None
|
||||
try:
|
||||
config = get_connection_details()
|
||||
conn = mysql.connector.connect(
|
||||
host=config.get('Host'),
|
||||
port=config.get('Port'),
|
||||
user=config.get('Username'),
|
||||
password=config.get('Password'),
|
||||
database=config.get('Database')
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("TRUNCATE TABLE extension_data")
|
||||
conn.commit()
|
||||
print("Table 'extension_data' truncated successfully.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
finally:
|
||||
if conn and conn.is_connected():
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
truncate_table()
|
Reference in New Issue
Block a user