38 lines
2.2 KiB
Python
38 lines
2.2 KiB
Python
|
|
import pymysql
|
||
|
|
|
||
|
|
def q(db, sql):
|
||
|
|
conn = pymysql.connect(host="10.8.0.252", user="root", password="Hbhyg731024@", database=db, charset="utf8mb4")
|
||
|
|
cur = conn.cursor()
|
||
|
|
cur.execute(sql)
|
||
|
|
rows = cur.fetchall()
|
||
|
|
conn.close()
|
||
|
|
return rows
|
||
|
|
|
||
|
|
for db in ("pms_dev", "pms"):
|
||
|
|
print("==== ", db)
|
||
|
|
for r in q(db, """
|
||
|
|
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE,
|
||
|
|
IFNULL(CAST(COLUMN_DEFAULT AS CHAR),'<NULL>') AS dflt,
|
||
|
|
COLUMN_TYPE, COLUMN_COMMENT
|
||
|
|
FROM information_schema.COLUMNS
|
||
|
|
WHERE TABLE_SCHEMA = '%s'
|
||
|
|
AND ((TABLE_NAME='charge_records' AND COLUMN_NAME IN ('energy','start_time','end_time'))
|
||
|
|
OR (TABLE_NAME='energy_stats' AND COLUMN_NAME='total_energy')
|
||
|
|
OR (TABLE_NAME='download_tasks' AND COLUMN_NAME='completed_at')
|
||
|
|
OR (TABLE_NAME='organizations' AND COLUMN_NAME='parent_id'))
|
||
|
|
ORDER BY TABLE_NAME, COLUMN_NAME""" % db):
|
||
|
|
print(" ", r)
|
||
|
|
|
||
|
|
print("==== pms_dev data")
|
||
|
|
print("charge_records:", q("pms_dev", "SELECT id, compartment_id, cabinet_id, start_time, end_time, energy FROM charge_records"))
|
||
|
|
print("download_tasks:", q("pms_dev", "SELECT id, task_type, status, completed_at FROM download_tasks"))
|
||
|
|
print("organizations(parent_id not null):", q("pms_dev", "SELECT COUNT(*) FROM organizations WHERE parent_id IS NOT NULL"))
|
||
|
|
print("pms organizations count:", q("pms", "SELECT COUNT(*) FROM organizations"))
|
||
|
|
print("pms fk/index on organizations.parent_id:", q("pms", "SELECT INDEX_NAME, COLUMN_NAME, NON_UNIQUE FROM information_schema.STATISTICS WHERE TABLE_SCHEMA='pms' AND TABLE_NAME='organizations'"))
|
||
|
|
print("pms create table organizations:\n", q("pms", "SHOW CREATE TABLE organizations")[0][1])
|
||
|
|
print("pms_dev create table organizations:\n", q("pms_dev", "SHOW CREATE TABLE organizations")[0][1])
|
||
|
|
print("pms create table charge_records:\n", q("pms", "SHOW CREATE TABLE charge_records")[0][1])
|
||
|
|
print("pms_dev create table charge_records:\n", q("pms_dev", "SHOW CREATE TABLE charge_records")[0][1])
|
||
|
|
print("pms_dev create table download_tasks:\n", q("pms_dev", "SHOW CREATE TABLE download_tasks")[0][1])
|
||
|
|
print("pms create table download_tasks:\n", q("pms", "SHOW CREATE TABLE download_tasks")[0][1])
|