python mysql

#!/usr/bin/python
#-*- coding:utf-8 -*-

import MySQLdb as mdb

con=None

try:
   con=mdb.connect('localhost','root','123','test')
   cur=con.cursor()
   cur.execute("select version()")
   data=cur.fetchone()
   print data
finally:
   if con:
      con.close()

 

你可能感兴趣的:(python mysql)