Python——鏈接操做數據庫

1.安裝MySQL驅動程序。下載自動安裝包,雙擊安裝便可,很是簡單。數據庫

2.鏈接MySQL,下面是Python示例代碼。fetch

import MySQLdbconn=MySQLdb.connect(host='localhost',          user='root',          passwd='本身密碼',          db='數據庫名稱')cursor = conn.cursor()cursor.execute ("SELECT VERSION()")row = cursor.fetchone ()print "server version:", row[0]cursor.close()conn.close()