python鏈接mysql


```
#coding=utf-8
import MySQLdb
conn= MySQLdb.connect(
       host='localhost',
       port = 3306,
       user='root',
       passwd='123456',
       db ='test',
       )
cur = conn.cursor()
#得到表中有多少條數據
aa=cur.execute("select * from student")
print aa
#打印表中的多少數據
info = cur.fetchmany(aa)
for ii in info:
   print ii
cur.close()
conn.commit()
conn.close()
```ide

相關文章
相關標籤/搜索