因为懒,所以不想用SQLyog,用Python写了一个快速执行SQL命令的程序:
import pymysql,sys class dealMySQL(object): ‘PyMysql‘ version = ‘Version:0.1‘ author = ‘Author: August‘ def __init__(self): pass @classmethod def execute(self,sql): ‘execute SQL command!‘ try: conn = pymysql.Connect(host=‘localhost‘,user=‘root‘,passwd=‘‘,db=‘sql_‘,port=3306,charset=‘utf8‘) cur = conn.cursor() except pymysql.err.InternalError as err: print("Can not connect MySQL:%r"%err) sys.exit() except pymysql.err.OperationalError as err: print("Can not connect MySQL:%r"%err) sys.exit() try: cur.execute(sql) conn.commit() for x in cur: print(x) print("success!") except: print("Error! Please check your SQL!") cur.close() conn.close()
本文出自 “AiCCDD” 博客,请务必保留此出处http://520ccdd.blog.51cto.com/3926314/1708105
原文地址:http://520ccdd.blog.51cto.com/3926314/1708105