Install the required modules.
$ sudo yum -y install python-setuptools
$ sudo yum -y install python-devel
$ sudo easy_install pip
$ sudo pip install MySQL-python
I will test
mysql_test.py
import MySQLdb
connection = MySQLdb.connect(db="python_test", user="root")
cursor = connection.cursor(cursorclass=MySQLdb.cursors.DictCursor)
cursor.execute("select * from users")
result = cursor.fetchall()
print(result)
cursor.close()
connection.close()
result:
$ python mysql_test.py
({'id': 1L, 'name': 'user1'}, {'id': 2L, 'name': 'user2'})
Recommended Posts