There are many ways to connect to MYSQL in python 3.2, such as using mysqldb and pymysql. This document describes how to connect to MYSQL using Pymysql.
1. Install pymysql
· Ensure that python3.2 is correctly installed
· Download installation package from https://pypi.python.org/pypi/PyMySQL3
· Decompress the package to the specified path
· Enter the installation directory in command line mode and execute Python setup. py installCommand
2 SimpleSample
'''Created onDec 17,201 3 @ author: aihua. sun ''' importpymysql; defaccess_mysql (): conn = pymysql. connect (host = 'localhost', port = 3306, user = 'root', db = 'test') cur = conn. cursor () cur.exe cute ("SELECT * FROM dictionarylimit 10") for r in cur: print ("row_number:" + str (cur. rownumber) print ("id:" + str (r [0]) + "key:" + str (r [1]) + "mean: "+ str (r [2]) cur. close () conn. close () if _ name __= = '_ main _': access_mysql ();
3 Referenceresources
Http://pymssql.sourceforge.net/ref_pymssql.php