Quantcast
Channel: Developer Feed - Snippet
Viewing all articles
Browse latest Browse all 178

How to check the version of MySQL database using Python?

$
0
0

  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()

Viewing all articles
Browse latest Browse all 178

Trending Articles