溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時(shí)間:2020-10-18 03:42:29 來源:腳本之家 閱讀:150 作者:weixin_43614688 欄目:開發(fā)技術(shù)

本文實(shí)例為大家分享了由Python編寫的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ù)庫地址
  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ù)庫').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ù)庫
  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語句')
  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編寫的MySQL管理工具詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)億速云網(wǎng)站的支持!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI