"Install"
Install MySQL
Install MySQL Needless to say, download the installation is, there is no special need to pay attention to the place.
One: Click to open the link
"Examples"
# coding=utf-8import mysqldb# Query number def Count (cur): Count=cur.execute (' select * from Student ') print ' There have%s rows R Ecord '% count #插入def insert (cur): sql = "INSERT into Student (id,name,age,sex) VALUES (%s,%s,%s,%s)" param = (2, ' Xiaom ing ', ' 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 (c UR): 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 "After Insert" #查询 Select (cur) #更新 update (cur) print "updated" #查询 Select (cur) #删除 DeLete (cur) print "deleted" #查询 Select (cur) cur.close () conn.close () except Mysqldb.error,e:print "Mysql Erro R%d:%s "% (E.args[0], e.args[1])
[Python] Python operation MySQL