Skip to content

Instantly share code, notes, and snippets.

@stefanmonkey
Created January 8, 2014 07:04
Show Gist options
  • Save stefanmonkey/8312907 to your computer and use it in GitHub Desktop.
Save stefanmonkey/8312907 to your computer and use it in GitHub Desktop.
MySQLdb module
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb as mdb
import sys
try:
con = mdb.connect('localhost', 'testuser', '123456', 'testdb')
cur = con.cursor()
cur.execute('select version()')
ver = cur.fetchone()
print "Database version : %s " % ver
except mdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit(1)
finally:
if con:
con.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment