| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import pymysql
- from pathlib import Path
- from openpyxl import Workbook
- out = Path(r"d:/Projects/Ai-DOP/SourceCode/ai-dop-platform/docs/db/aidopcore_远端落库表字段说明.xlsx")
- conn = pymysql.connect(host='106.14.73.46', port=3306, user='aidopremote', password='AidOp#Remote2026$Secure', charset='utf8mb4', autocommit=True)
- try:
- with conn.cursor() as cur:
- cur.execute("""
- SELECT table_name, table_comment
- FROM information_schema.tables
- WHERE table_schema='aidopcore' AND table_name LIKE 'ado\\_%'
- ORDER BY table_name
- """)
- tables = cur.fetchall()
- wb = Workbook()
- ws1 = wb.active
- ws1.title = '表清单'
- ws1.append(['序号','表名','表说明'])
- for i, (t, c) in enumerate(tables, 1):
- ws1.append([i, t, c])
- ws2 = wb.create_sheet('字段说明')
- ws2.append(['表名','字段序号','字段名','类型','可空','默认值','字段说明'])
- for t, _ in tables:
- cur.execute("""
- SELECT ordinal_position, column_name, column_type, is_nullable, column_default, column_comment
- FROM information_schema.columns
- WHERE table_schema='aidopcore' AND table_name=%s
- ORDER BY ordinal_position
- """, (t,))
- cols = cur.fetchall()
- for pos, name, ctype, nullable, dft, cm in cols:
- ws2.append([t, pos, name, ctype, '是' if nullable=='YES' else '否', '' if dft is None else str(dft), cm])
- wb.save(out)
- print(str(out))
- print(f'tables={len(tables)}')
- finally:
- conn.close()
|