python3.5 version is special, the previous version of MYSQLDB does not support 3.5, so use pymysql here
1. After decompression, run cmd, enter the pymysql3-0.5 directory, enter the Python setup.py install, perform the installation
2. Test after installation
1 Import Pymysql
If there is no error, it means that pymysql installed successfully, the following test with the database
3. Create database test, new table person, random fill in some data (here I use the SQLyog, convenient point)
4. Connect to the database
1 ImportPymysql2 3 #Open a database connection4db = Pymysql.connect (host="127.0.0.1", port=3306, user="Root", passwd="Mark", db="Test", charset="UTF8")5 6 #Create a Cursor object using the cursor () method cursor7cursor =db.cursor ()8 9 #Execute SQL Query using the Execute () methodTenCursor.execute ("SELECT * from person") One forDatainchcursor: A Print(data) - - #To close a database connection theDb.close ()
Run Results
python3.5 connecting MySQL