By default, the MySQLdb package is not installed. Do not believe it? You can see the code similar to the following.
Copy codeThe Code is 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
In this case, we have to install the MySQLdb package. The installation procedure is as follows:
1. Download MySQL for Python
Address: http://sourceforge.net/projects/mysql-python/files/mysql-python/
I installed version 1.2.3 here.
Copy codeThe Code is as follows: wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
2. Decompress
Copy codeThe Code is as follows: tar zxvf MySQL-python-1.2.3.tar.gz
3. Installation
Copy codeThe Code is as follows: $ cd MySQL-python-1.2.3
$ Python setup. py build
$ Python setup. py install
Note:
If the following error occurs during execution: python setup. py build:
Copy codeThe Code is as follows: EnvironmentError: mysql_config not found
First, find the location of mysql_config, and use
Find/-name mysql_config, for example, in/usr/local/mysql/bin/mysql_config
Modify the setup_posix.py file in 26 rows:
Modify mysql_config.path = "mysql_config":
Copy codeThe Code is as follows: mysql_config.path = "/usr/local/mysql/bin/mysql_config"
Save and run the following command again:
Copy codeThe Code is as follows: python setup. py build
Python setup. py install
OK. This is all done.