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.