dump_login_schema.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. """查看登录相关表结构"""
  3. import re
  4. import pymysql
  5. from pathlib import Path
  6. from _root import ROOT
  7. yml = Path(str(ROOT / "yoshop-java/src/main/resources/application.yml"))
  8. text = yml.read_text(encoding="utf-8")
  9. pwds = re.findall(r"password:\s*(.+)", text)
  10. pwd = pwds[0].strip().strip('"\'')
  11. conn = pymysql.connect(host="192.168.1.177", port=3306, user="root", password=pwd, database="shop")
  12. cur = conn.cursor()
  13. for t in ("yoshop_store_user", "yoshop_store", "yoshop_store_role"):
  14. print("=" * 20, t)
  15. cur.execute(
  16. "SELECT column_name, column_type, is_nullable, column_default FROM information_schema.columns "
  17. "WHERE table_schema='shop' AND table_name=%s ORDER BY ordinal_position", (t,))
  18. for cn, ct, nl, df in cur.fetchall():
  19. print(f" {cn:22s} {ct:20s} null={nl} default={df}")
  20. print("\n=== store_user 数据 ===")
  21. cur.execute("SELECT store_user_id, user_name, real_name, is_super, is_delete, store_id, LEFT(password,10) FROM yoshop_store_user")
  22. for r in cur.fetchall():
  23. print(r)
  24. print("\n=== store 数据 ===")
  25. cur.execute("SELECT store_id, store_name, is_delete, is_recycle FROM yoshop_store")
  26. for r in cur.fetchall():
  27. print(r)
  28. conn.close()