Breaking News
Home / Python / How to check the version of MySQL database using Python?

How to check the version of MySQL database using Python?

  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import MySQLdb as mdb
  5. import sys
  6.  
  7. con = None
  8.  
  9. try:
  10.  
  11.     con = mdb.connect(‘localhost’, ‘username’,
  12.         ‘password’, ‘dbname’);
  13.  
  14.     cur = con.cursor()
  15.     cur.execute("SELECT VERSION()")
  16.  
  17.     data = cur.fetchone()
  18.    
  19.     print "Database version : %s " % data
  20.    
  21. except mdb.Error, e:
  22.  
  23.     print "Error %d: %s" % (e.args[0],e.args[1])
  24.     sys.exit(1)
  25.    
  26. finally:    
  27.        
  28.     if con:    
  29.  
  30.         con.close()
[pb_builder]

Check Also

python-stop-watch

A StopWatch Game in Python

Project Build a simple digital stopwatch that keep track of the time in tenths of …

Advertisment ad adsense adlogger