由Python编写的MySQL管理工具代码实例 本文实例为大家分享了由Python编写的MySQL管理工具的具体代码,供大家参考,具体内容如下 import pymysql import pandas as pd from tkinter import Label,StringVar,Entry,Tk,Button from tkinter.simpledialog import askstring def Entry_address(): #输入数据库地址 root=Tk() l1=Label(root,text='服务器:').grid(column=0,row=0) text1=StringVar() Entry(root,textvariable=text1).grid(column=1,row=0) l2=Label(root,text='用户名:').grid(column=0,row=1) text2=StringVar() Entry(root,textvariable=text2).grid(column=1,row=1) l3 = Label(root, text='密码').grid(column=0, row=2) text3 = StringVar() Entry(root, textvariable=text3,show='*').grid(column=1, row=2) l4 = Label(root, text='数据库').grid(column=0, row=3) text4 = StringVar() Entry(root, textvariable=text4).grid(column=1, row=3) Button(root,text='确定',command=lambda:root.destroy()).grid(column=1,row=4) root.mainloop() return text1.get(),text2.get(),text3.get(),text4.get() def connect_database(): #连接数据库 h,u,p,d=Entry_address() connect = pymysql.connect(host=h, user=u, password=p, db=d) cursor = connect.cursor(cursor=pymysql.cursors.DictCursor) return cursor def select_data(): #操作数据 cursor=connect_database() # query='insert into person (fname,lname) values(%s,%s)' # values=('lu','Cachy')##元组只能存储单一数据类型 # cursor.execute(query,values) root1=Tk() root1.withdraw() query=askstring('hello','输入SQL语句') root1.destroy() root1.mainloop() cursor.execute(query) cursor.connection.commit() #获取权限 a = cursor.fetchall() #从游标中取出数据 cursor.close() c=pd.DataFrame(a) print(c) if __name__=='__main__': select_data() 以上所述是小编给大家介绍的由Python编写的MySQL管理工具详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对中文源码网网站的支持!