37 lines
970 B
Python
37 lines
970 B
Python
|
|
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()
|