1, 下载MySQLdb:
2, 如下python代码
#!/usr/bin/pythonimport MySQLdbdb = MySQLdb.connect(host="localhost", # your host, usually localhost user="john", # your username passwd="megajonhy", # your password db="jonhydb") # name of the data base# you must create a Cursor object. It will let# you execute all the query you needcur = db.cursor() # Use all the SQL you likecur.execute("SELECT * FROM YOUR_TABLE_NAME")# print all the first cell of all the rowsfor row in cur.fetchall() : print row[0]