Home » Uncategorized » Python and MySQL

Python and MySQL

This is quite a bit easier in the set up than working with Oracle. Python comes with built in support for MySQL. For Oracle, I needed to download the drivers and support (Adding the Oracle modules for Python on Linux)

import mysql.connector

config = {
'user': 'username',
'password': 'password',
'host': '127.0.0.1',
'database': 'test',
'raise_on_warnings': True,
}

cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()

# read data:
query = ("SELECT * FROM employee")
cursor.execute(query)

for (name,ss) in cursor:
print(name+" "+ss)

# close database
cursor.close()
cnx.close()

Leave a Reply