#!/usr/bin/env python #--*-- coding:utf-8 --*-- __author__ = 'Kevin' import MySQLdb as mdb con = None try: con = mdb.connect('localhost','root','redhat','test') cur = con.cursor() cur.execute("SELECT VERSION()") data = cur.fetchone() print "Database version: %s" % data finally: if con: con.close()
Result:
Database version: 5.6.27