When Python connects and uses MySQL, it needs to call the MySQLdb module, which is the interface for the Python link MySQL database, which implements the Python database API specification V2.0, built on the MySQL C API.
MYSQLDB module in different platforms, the installation method is not the same, here the main introduction of the installation of Linux, Https://pypi.python.org/pypi/MySQL-python can choose the appropriate version here, decompression installation.
Installation steps:
1, select the appropriate version and check the relevant path here to choose Version Mysql-python-1.2.5.zip, the following is the download path and process. wget https://pypi.python.org/packages/a5/e9/ 51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/mysql-python-1.2.5.zip--2016-10-08 21:34:56- - https://pypi.python.org/packages/a5/e9/ 51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/mysql-python-1.2.5.zipresolving Pypi.python.org... 151.101.76.223, 2a04:4e42:12::223connecting to pypi.python.org| 151.101.76.223|:443... connected. http request sent, awaiting response... 200 oklength: 108935 (106K) [application/octet-stream]Saving to: "Mysql-python-1.2.5.zip" 100%[============================ ==========================>] 108,935 --.-k/s in 0.1s 2016-10-08 21:34:57 (1.00 mb/s) - "Mysql-python-1.2.5.zip " saved [108935/108935][[email protectEd] python]# ls mysql.py mysql-python-1.2.5.zip Decompression:[[email protected] python]# unzip mysql-python-1.2.5.zip archive: mysql-python-1.2.5.zip inflating: mysql-python-1.2.5/gpl-2.0 inflating: mysql-python-1.2.5/ History inflating: mysql-python-1.2.5/install inflating: mysql-python-1.2.5/manifest.in inflating: mysql-python-1.2.5/metadata.cfg inflating: MySQL-python-1.2.5/PKG-INFO inflating: mysql-python-1.2.5/pymemcompat.h inflating: mysql-python-1.2.5/readme.md inflating: MySQL-python-1.2.5/setup.cfg inflating: mysql-python-1.2.5/setup.py inflating: mysql-python-1.2.5/setup_common.py inflating: mysql-pythoN-1.2.5/switch to unzip directory installation: Use command python setup.py build && python setup.py install Installation Error: [[email protected] mysql-python-1.2.5]# python setup.py buildtraceback (most recent Call last): file "setup.py", line 7, in <module> import setuptoolsimporterror: no module named setuptools hint missing setuptools can be installed in the command and the same as above, and so the final execution completed without error, installation success, we continue to install the above. python setup.py buildrunning buildrunning build_pycreating Buildcreating build/libcopying pkg_resources.py -> build/libcopying easy_ install.py -> build/libcopying site.py -> build/libcreating build/lib/ Setuptoolscopying setuptools/package_index.py -> build/lib/setuptoolscopying setuptools/depends.py -> build/lib/setuptoolscopying setuptools/ Extension.py -> build/lib/setuptoolscopying setuptools/__init__.py -> build/lib /set ... installed /usr/local/python2.7.11/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.eggprocessing dependencies for setuptools==0.6c11finished processing dependencies for SETUPTOOLS==0.6C11[[EMAIL&NBSP;PROTECTED]&NBSP;SETUPTOOLS-0.6C11]#&NBSP;CD&NBSP;&NBSP, .... Continue installation mysql-python appears error: command ' gcc ' failed with exit status 1 You can use the following command to resolve yum install gcc python-devel mysql-devel libxml2 libxml2-dev Libxslt* zlib gcc openssl
After the installation is complete the inspection:
Call the python command in the shell window and execute it without error.
Import MySQLdb
Centos6.7 installation of Python connection MySQL environment troubleshooting