import pymysql SQL = """ SELECT TABLE_NAME, COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, IFNULL(CAST(COLUMN_DEFAULT AS CHAR),'') AS dflt FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME IN ('charge_orders','charge_records','download_tasks','energy_stats') ORDER BY TABLE_NAME, ORDINAL_POSITION """ for db in ("pms_dev", "pms"): c = pymysql.connect(host="10.8.0.252", user="root", password="Hbhyg731024@", database=db) cur = c.cursor() cur.execute(SQL, (db,)) print("==", db) for r in cur.fetchall(): print(" %-16s %-18s %-14s null=%-4s default=%s" % r) c.close()