国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

[python]Python操作MySQL

2019-11-14 17:25:39
字體:
來源:轉載
供稿:網友

【安裝】

安裝MySQL

安裝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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# coding=utf-8
import MySQLdb
 
#查詢數量
def Count(cur):
   count=cur.execute('select * from Student')
   PRint 'there has %s rows record' % count
    
#插入
def Insert(cur):
   sql = "insert into Student(ID,Name,Age,Sex)values(%s,%s,%s,%s)"
   param = (2,'xiaoming',24,'boy')
   cur.execute(sql,param)
 
#查詢
def  Select(cur): 
   n = cur.execute("select * from Student")   
   print "------"
   for row in cur.fetchall():   
      for r in row:   
         print r
      print "------"   
#更新
def Update(cur):
   sql = "update Student set Name = %s where ID = 2"  
   param = ("xiaoxue")   
   count = cur.execute(sql,param)
 
#刪除
def Delete(cur):   
   sql = "delete from Student where Name = %s"  
   param =("xiaoxue")   
   n = cur.execute(sql,param)  
  
try:
   conn=MySQLdb.connect(host='localhost',user='root',passwd='123456',db='python',port=3306)
   cur=conn.cursor()
   #數量
   Count(cur)
   #查詢
   Select(cur)
   #插入
   Insert(cur)
   print "插入之后"
   #查詢
   Select(cur)
   #更新
   Update(cur)
   print "更新之后"
   #查詢
   Select(cur)
   #刪除
   Delete(cur)
   print "刪除之后"
   #查詢
   Select(cur)
    
   cur.close()
   conn.close()
    
except MySQLdb.Error,e:
   print "Mysql Error %d: %s" % (e.args[0], e.args[1])


/

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 普安县| 怀远县| 宿迁市| 尉氏县| 湘阴县| 汝南县| 高邮市| 兴宁市| 富民县| 长海县| 桃园市| 福贡县| 丹东市| 冀州市| 同仁县| 科技| 蒙阴县| 连江县| 宣城市| 光泽县| 玉屏| 黔南| 博兴县| 凤台县| 沈丘县| 康保县| 潞西市| 祥云县| 马关县| 新沂市| 综艺| 铁力市| 清水河县| 盐城市| 屏山县| 巴马| 肃宁县| 巴林左旗| 连平县| 佛山市| 离岛区|