星期四, 4月 25, 2013

Access MySQL db from python

It's simpler than I expect.

>>> import MySQLdb
>>> db = MySQLdb.connect("server ip", "username", "password", "db name")
>>> cursor = db.cursor()
>>> cursor.execute("sql statement")
>>> data = cursor.fetchone()

沒有留言: