python3.4 connection MySQL database under Win7 system
1. Download the latest Python program to the official Python website. According to the system there are 32, 64 bits.
Directly next, you can install successfully.
2. Download the ez_setup.py file in the Python website.
This tool is a Python Management Pack tool that allows you to download many services.
Please download the relevant files according to the system.
Download the ez_setup.py file in the https://pypi.python.org/pypi/setuptools#windows-simplified URL.
3. Execute the python ez_setup.py file in Python, and if you do not configure an environment variable, you can find Python.exe in the Python installation path to execute the above command in this directory.
After the command executes successfully, the Easy_install.exe Toolkit is installed in the Python installation directory
4. Execute at cmd command line: Easy_install.exe PYMYSQL3
If the command is not found, the switch service is executed under the Python installation directory/scripts/. If there is no easy_install.exe in this directory, it proves that the previous step was not successfully installed.
5.
The contents of the Python program are as follows: Import Pymysql
conn = Pymysql.connect (user= ' root ', passwd= ' root ',
host= ' localhost ', db= ' zjctest ')
cur = conn.cursor ()
Cur.execute ("SELECT * from ZJC")
For R in Cur:
Print ("Row_number:", (Cur.rownumber))
Print ("ID:" +str (r[0]) + "Name:" +str (r[1]) + "Age:" +str (r[2))
Cur.close ()
Conn.close ()
Python Learning (Python) operation MySQL Database _ installation