本文实例为大家分享了由python编写的mysql管理工具的具体代码,供大家参考,具体内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
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管理工具详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:https://blog.csdn.net/weixin_43614688/article/details/89061548