list_tables.py 595 B

123456789101112131415
  1. # -*- coding: utf-8 -*-
  2. """列出库内所有表"""
  3. import re
  4. import pymysql
  5. YML = r"C:\Users\Administrator\WorkBuddy\2026-10-17-12-27-10\java-rewrite\yoshop-java\src\main\resources\application.yml"
  6. text = open(YML, encoding="utf-8").read()
  7. pwd = re.findall(r"password:\s*(.+)", text)[0].strip().strip("\"'")
  8. conn = pymysql.connect(host="192.168.1.177", port=3306, user="root", password=pwd, database="shop")
  9. cur = conn.cursor()
  10. cur.execute("SELECT table_name FROM information_schema.tables WHERE table_schema='shop' ORDER BY table_name")
  11. for (t,) in cur.fetchall():
  12. print(t)
  13. conn.close()