first_project
This commit is contained in:
44
check_table_schema.py
Normal file
44
check_table_schema.py
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
|
||||
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 check_table_schema():
|
||||
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'),
|
||||
charset='utf8mb4'
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
print("Querying schema for extension_data table...")
|
||||
cursor.execute("DESCRIBE extension_data")
|
||||
columns = cursor.fetchall()
|
||||
|
||||
print("\nTable Schema for 'extension_data':")
|
||||
for col in columns:
|
||||
print(f" Column: {col[0]}, Type: {col[1]}, Null: {col[2]}, Key: {col[3]}, Default: {col[4]}, Extra: {col[5]}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
finally:
|
||||
if conn and conn.is_connected():
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_table_schema()
|
||||
|
Reference in New Issue
Block a user