欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

由Python編寫(xiě)的MySQL管理工具代碼實(shí)例

 更新時(shí)間:2019年04月09日 14:07:10   作者:weixin_43614688  
這篇文章主要介紹了由Python編寫(xiě)的MySQL管理工具,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

本文實(shí)例為大家分享了由Python編寫(xiě)的MySQL管理工具的具體代碼,供大家參考,具體內(nèi)容如下

import pymysql
import pandas as pd
from tkinter import Label,StringVar,Entry,Tk,Button
from tkinter.simpledialog import askstring
def Entry_address():                        #輸入數(shù)據(jù)庫(kù)地址
  root=Tk()
  l1=Label(root,text='服務(wù)器:').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='數(shù)據(jù)庫(kù)').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():                       #連接數(shù)據(jù)庫(kù)
  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():                         #操作數(shù)據(jù)
  cursor=connect_database()
  # query='insert into person (fname,lname) values(%s,%s)'
  # values=('lu','Cachy')##元組只能存儲(chǔ)單一數(shù)據(jù)類型
  # cursor.execute(query,values)
  root1=Tk()
  root1.withdraw()
  query=askstring('hello','輸入SQL語(yǔ)句')
  root1.destroy()
  root1.mainloop()
  cursor.execute(query)
  cursor.connection.commit()                   #獲取權(quán)限
  a = cursor.fetchall()                      #從游標(biāo)中取出數(shù)據(jù)
  cursor.close()
  c=pd.DataFrame(a)
  print(c)
if __name__=='__main__':
  select_data()

以上所述是小編給大家介紹的由Python編寫(xiě)的MySQL管理工具詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論