Python under the MySQL module MYSQLDB installation detailed _python

Source: Internet
Author: User
By default, MYSQLDB packages are not installed, do not believe? See the code similar to the following you believe it.
Copy Code code as follows:
-bash-3.2#/usr/local/python2.7.3/bin/python get_cnblogs_news.py
Traceback (most recent call last):
File "get_cnblogs_news.py", line 9, in <module>
Import MySQLdb
Importerror:no module named MySQLdb

Then we have to install the MYSQLDB package. The installation is actually very simple, the following steps:
1. Download MySQL for Python
Address: http://sourceforge.net/projects/mysql-python/files/mysql-python/
I have a 1.2.3 version installed here.
Copy Code code as follows:
wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz

2, decompression
Copy Code code as follows:
Tar zxvf mysql-python-1.2.3.tar.gz

3, installation
Copy Code code as follows:
$ CD mysql-python-1.2.3
$ python setup.py Build
$ python setup.py Install

Note:
If you are executing: The Python setup.py build encounters the following error:
Copy Code code as follows:
Environmenterror:mysql_config not found

First find the location of the Mysql_config, using
Find/-name Mysql_config, like mine in/usr/local/mysql/bin/mysql_config
Modify the setup_posix.py file, on line 26:
Mysql_config.path = "Mysql_config" modified to:
Copy Code code as follows:
Mysql_config.path = "/usr/local/mysql/bin/mysql_config"

Save and then execute again:
Copy Code code as follows:
Python setup.py Build
Python setup.py Install

OK, here we go.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.