30 lines
807 B
Python
30 lines
807 B
Python
import pymysql
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
def show_tables():
|
|
conn = pymysql.connect(
|
|
host=os.getenv('DB_HOST', 'localhost'),
|
|
user=os.getenv('DB_USER', 'root'),
|
|
password=os.getenv('DB_PASSWORD', '45278434'),
|
|
database='PM_proto_test',
|
|
charset='utf8mb4',
|
|
cursorclass=pymysql.cursors.DictCursor
|
|
)
|
|
try:
|
|
with conn.cursor() as cursor:
|
|
cursor.execute("SHOW TABLES")
|
|
tables = cursor.fetchall()
|
|
print("Tables in PM_proto_test:")
|
|
for t in tables:
|
|
print(f" - {list(t.values())[0]}")
|
|
except Exception as e:
|
|
print(f"Error occurred: {e}")
|
|
finally:
|
|
conn.close()
|
|
|
|
if __name__ == "__main__":
|
|
show_tables()
|