#!/usr/bin/python3 # -*- coding: utf-8 -*- import pymysql db = pymysql.connect(host="222.73.129.15", port=31306, user="root", passwd="kepaiteng!QAZ", db="eq", charset="utf8") sqlname =input("请输入sqlname:") try: cursor = db.cursor() err =cursor.execute("select sqlstr from apisql where sqlname =%s",sqlname) sqlstr =cursor.fetchone() print(sqlstr[0]) write_file = open("%s.sql"%(sqlname), "w", encoding="utf-8").write(sqlstr[0]) except: print() db.close()