中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Python操作MySQL

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

安裝MySQL

安裝MySQL不用多說了,下載下來安裝就是,沒有特別需要注意的地方。

# coding=utf-8
import MySQLdb
 
#查詢數(shù)量
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()
   #數(shù)量
   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])

標簽: Mysql

版權(quán)申明:本站文章部分自網(wǎng)絡,如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:PHP 常用的header頭部定義

下一篇:JS數(shù)字金額大寫轉(zhuǎn)換(可以處理整數(shù),小數(shù),負數(shù))