因为懒,所以不想用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()
转载于:https://blog.51cto.com/520ccdd/1708105