dump_db.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. import subprocess, os
  3. mysql = r"D:\mysql-5.7\mysql-5.7.24-winx64\bin\mysql.exe"
  4. out = r"D:\IdeaProjects\mes-ahdy\mescloud\_apk_work\extracted"
  5. base = [
  6. mysql, "--user=root", "--password=123456", "--host=127.0.0.1", "--port=3306",
  7. "--database=mes_cloud_ahdy", "--default-character-set=utf8mb4", "--batch", "--raw"
  8. ]
  9. queries = {
  10. "db_categories.txt": "SELECT id, title, sort_order, status FROM mes_icons_category ORDER BY sort_order, title",
  11. "db_icons.txt": (
  12. "SELECT IFNULL(c.title,'未分类') AS category, i.title AS icon, i.mode, i.auth, i.status "
  13. "FROM mes_icons i LEFT JOIN mes_icons_category c ON c.id = i.category_id "
  14. "WHERE i.status='0' ORDER BY IFNULL(c.sort_order,9999), i.title"
  15. ),
  16. "db_menus.txt": (
  17. "SELECT tree_level, menu_name, menu_href, parent_code, menu_code "
  18. "FROM js_sys_menu WHERE status='0' AND is_show='1' AND menu_type IN ('1','0') "
  19. "ORDER BY tree_sorts, tree_sort"
  20. ),
  21. "db_hidden_menus.txt": (
  22. "SELECT tree_level, menu_name, menu_href, is_show, status "
  23. "FROM js_sys_menu WHERE menu_name LIKE '%扫码%' OR menu_name LIKE '%涂胶%' "
  24. "OR menu_name LIKE '%恢复%' OR menu_name LIKE '%样件%' OR menu_name LIKE '%物料批次%' "
  25. "OR menu_name LIKE '%钉钉%' OR menu_name LIKE '%GP12%' OR menu_name LIKE '%采购%' "
  26. "OR menu_name LIKE '%上下限%' OR menu_name LIKE '%工具寿命%'"
  27. ),
  28. }
  29. for fn, q in queries.items():
  30. data = subprocess.check_output(base + ["--execute", q], stderr=subprocess.STDOUT)
  31. if data.startswith(b"mysql:"):
  32. data = data.split(b"\n", 1)[1]
  33. path = os.path.join(out, fn)
  34. with open(path, "wb") as f:
  35. f.write(data)
  36. print("wrote", fn, len(data))