濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > python使用pymysql模塊操作MySQL

python使用pymysql模塊操作MySQL

熱門標(biāo)簽:大連crm外呼系統(tǒng) 梅州外呼業(yè)務(wù)系統(tǒng) 百度地圖標(biāo)注位置怎么修改 高德地圖標(biāo)注是免費(fèi)的嗎 老人電話機(jī)器人 地圖標(biāo)注視頻廣告 洪澤縣地圖標(biāo)注 北京電信外呼系統(tǒng)靠譜嗎 無錫客服外呼系統(tǒng)一般多少錢

實(shí)例一:插入數(shù)據(jù)

import pymysql
import tkinter as tk

conn = pymysql.connect(host='localhost', user='root', passwd='root', db='okzl', charset='utf8')

master = tk.Tk()
master.title("插入供應(yīng)商信息")
master.geometry('350x300')
tk.Label(master, text='cName').place(x=30,y=10)
tk.Label(master, text='address').place(x=30,y=40)
tk.Label(master, text='linkman').place(x=30,y=70)
tk.Label(master, text='linkPhone').place(x=30,y=100)
tk.Label(master, text='credit').place(x=30,y=130)
tk.Label(master, text='remark').place(x=30,y=160)
in1=tk.Entry(master, width=30).place(x=100,y=10)
in2=tk.Entry(master, width=30).place(x=100,y=40)
in3=tk.Entry(master, width=30).place(x=100,y=70)
in3=tk.Entry(master, width=30).place(x=100,y=100)
in3=tk.Entry(master, width=30).place(x=100,y=130)
in3=tk.Entry(master, width=30).place(x=100,y=160)

def insert():
    cur = conn.cursor()  # 伸出手
    sql1 = "insert into pro(cName,address,linkman,linkPhone,credit,remark) values(%s,%s,%s,%s,%s,%s)"
    temp2 = ( )
    cur.execute(sql1, temp2)
    conn.commit()
    cur.close()

tk.Button(master,text='插入',width=8,command=insert).place(x=140,y=220)

master.mainloop()
conn.close()

成功插入數(shù)據(jù)

實(shí)例二:獲取某個(gè)表全部數(shù)據(jù)

import pymysql

conn = pymysql.connect(host='localhost', user='root', passwd='root', db='okzl', charset='utf8')
cur = conn.cursor()

cur.execute('select * from pro')
data = cur.fetchall()

cur.close()
print(data)
conn.close()

實(shí)例三:根據(jù)cName模糊搜索

import pymysql
import tkinter as tk

conn = pymysql.connect(host='localhost', user='root', passwd='root', db='okzl', charset='utf8')  # 連接數(shù)據(jù)庫(kù)

master = tk.Tk()
master.title("搜索某客戶信息")
master.geometry('350x300')

e = tk.Entry(master)
e.pack(padx=20, pady=20)


def tosearch():
    cur = conn.cursor()
    temp2 = (e.get(), "%" + e.get() + "%")
    cur.execute("select * from pro where cName like %s or cName like %s ", temp2)
    data = cur.fetchall()
    cur.close()
    print(data)


tk.Button(master, text='搜索', width=8, command=tosearch).pack(padx=20, pady=50)

master.mainloop()

conn.close()

實(shí)例四:修改數(shù)據(jù)

根據(jù)數(shù)據(jù)庫(kù)自動(dòng)給數(shù)據(jù)生成的id來確認(rèn)目標(biāo)和修改數(shù)據(jù)

import pymysql
import tkinter as tk

conn = pymysql.connect(host='localhost', user='root', passwd='root', db='okzl', charset='utf8')

master = tk.Tk()
master.title("修改供應(yīng)商信息")
master.geometry('350x300')
tk.Label(master, text='cName').place(x=30,y=10)
tk.Label(master, text='address').place(x=30,y=40)
tk.Label(master, text='linkman').place(x=30,y=70)
tk.Label(master, text='linkPhone').place(x=30,y=100)
tk.Label(master, text='credit').place(x=30,y=130)
tk.Label(master, text='remark').place(x=30,y=160)
tk.Label(master, text='目標(biāo)id').place(x=30,y=190)
in1=tk.Entry(master, width=30)
in1.place(x=100,y=10)
in2=tk.Entry(master, width=30)
in2.place(x=100,y=40)
in3=tk.Entry(master, width=30)
in3.place(x=100,y=70)
in4=tk.Entry(master, width=30)
in4.place(x=100,y=100)
in5=tk.Entry(master, width=30)
in5.place(x=100,y=130)
in6=tk.Entry(master, width=30)
in6.place(x=100,y=160)
in7=tk.Entry(master, width=30)
in7.place(x=100,y=190)

def update():
    cur = conn.cursor()  # 伸出手
    sql1 = "update pro set cName=%s, address=%s,linkman=%s,linkPhone=%s,credit=%s,remark=%s where id=%s"
    temp2 = (in1.get(),in2.get(),in3.get(),in4.get(),in5.get(),in6.get(),in7.get())
    cur.execute(sql1, temp2)
    conn.commit()
    cur.close()


tk.Button(master,text='確認(rèn)修改',width=8,command=update).place(x=140,y=220)

master.mainloop()
conn.close()

實(shí)例五:刪除數(shù)據(jù)

這里是根據(jù)id刪除

sql1 = "delete from pro where id=%s"
temp1 = str(n)
cur.execute(sql1, temp1)
conn.commit()
cur.close()

上述實(shí)例均為基礎(chǔ)實(shí)現(xiàn)操作舉例,實(shí)際操作中可根據(jù)需求更改程序和sql語(yǔ)句實(shí)現(xiàn)目標(biāo)效果

以上就是python使用pymysql模塊操作MySQL的詳細(xì)內(nèi)容,更多關(guān)于python 用pymysql操作MySQL的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

您可能感興趣的文章:
  • 利用python中pymysql操作MySQL數(shù)據(jù)庫(kù)的新手指南
  • Python接口自動(dòng)化淺析pymysql數(shù)據(jù)庫(kù)操作流程
  • pymysql實(shí)現(xiàn)增刪改查的操作指南(python)
  • python 基于PYMYSQL使用MYSQL數(shù)據(jù)庫(kù)
  • python pymysql庫(kù)的常用操作
  • Python pymysql模塊安裝并操作過程解析
  • python數(shù)據(jù)庫(kù)操作mysql:pymysql、sqlalchemy常見用法詳解
  • 在python中使用pymysql往mysql數(shù)據(jù)庫(kù)中插入(insert)數(shù)據(jù)實(shí)例
  • Python使用pymysql模塊操作mysql增刪改查實(shí)例分析
  • python之pymysql模塊簡(jiǎn)單應(yīng)用示例代碼
  • wxpython+pymysql實(shí)現(xiàn)用戶登陸功能
  • 在Python中使用MySQL--PyMySQL的基本使用方法
  • Python 中使用 PyMySQL模塊操作數(shù)據(jù)庫(kù)的方法
  • 使用python連接mysql數(shù)據(jù)庫(kù)之pymysql模塊的使用
  • Python pymysql操作MySQL詳細(xì)

標(biāo)簽:泉州 清遠(yuǎn) 安慶 吉林 洛陽(yáng) 怒江 岳陽(yáng) 長(zhǎng)春

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《python使用pymysql模塊操作MySQL》,本文關(guān)鍵詞  python,使用,pymysql,模塊,操作,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《python使用pymysql模塊操作MySQL》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于python使用pymysql模塊操作MySQL的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    永顺县| 延津县| 芦溪县| 黄大仙区| 巴里| 山东| 河津市| 宣汉县| 利津县| 嵊泗县| 龙州县| 巴林右旗| 玉田县| 乌鲁木齐市| 东港市| 宝山区| 九江县| 开江县| 万山特区| 乌苏市| 康乐县| 和龙市| 凤台县| 连州市| 六枝特区| 中超| 恭城| 汉沽区| 牟定县| 周宁县| 溧阳市| 泽州县| 连平县| 奉贤区| 贵州省| 怀远县| 普定县| 抚宁县| 咸宁市| 北宁市| 玉环县|