Installieren Sie die erforderlichen Module.
$ sudo yum -y install python-setuptools
$ sudo yum -y install python-devel
$ sudo easy_install pip
$ sudo pip install MySQL-python
Ich werde testen
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()
Ergebnis:
$ python mysql_test.py
({'id': 1L, 'name': 'user1'}, {'id': 2L, 'name': 'user2'})
Recommended Posts