Looking for more info? Follow our learning guides and get started!

Check Mysql database version in Python


#!/usr/bin/python # -*- coding: utf-8 -*- import MySQLdb as mdb import sys con = None try: con = mdb.connect('localhost', 'username','password', 'dbname'); cur = con.cursor() cur.execute("SELECT VERSION()") data = cur.fetchone() print ("Database version : %s ") % data except e: print ("Error %d: %s") % (e.args[0],e.args[1]) sys.exit(1) finally: if con: con.close()

Loading Please Wait...