Install Python mysqldb in Linux. I found it really hurts to install it by compiling it, but it's just a matter of time, all kinds of problems ......
There are two methods:
A. quick installation
B. compile it by yourself
1. The fastest and easiest way (in a hurry)
Sudo Yum install mysql-Python
Possible problems:
>>> Import mysqldb
Traceback (most recent call last ):
File "<stdin>", line 1, in?
File "mysqldb/_ init _. py", line 22, in?
Raise importerror ("this is mysqldb version % s, but _ MySQL is version % R" %
Importerror: This is mysqldb version (1, 2, 3, 'final', 0), but _ MySQL is version (1, 2, 1, 'final', 1)
Cause: the previous compilation method is used for installation. The following is 1.2.3, but yum is currently used for a maximum of 1.2.1. Conflict
Solution: delete compiled files
Rm-RF Co., MySQL-python-1.2.3/
Proceed
>>> Import mysqldb
If no error exists, it indicates the operation is successful.
2. Compile and install it by yourself (if you have time... Token)
Required:
A. GCC
B. setuptools
Wget-O setuptools-0.6c8.tar.gz unzip sudo easy_install.py [or Python setup. py build & sudo Python setup. py install]
C. Python-Dev in sudo apt-Get install Python-Dev
Otherwise, an exception occurs: Fatal error: Python. h: the file or directory does not exist.
Steps:
A. Download: wget http://sourceforge.net/projects/mysql-python/files/latest/download
B.
$ Tar xfz MySQL-python-1.2.3.tar.gz
$ MySQL-python-1.2.3 CD
$ Whereis mysql_config
Mysql_config:/usr/bin/mysql_config
$ Vim site. cfg
Modify mysql_config to the MySQL configuration file path/usr/bin/mysql_config
Also modify
Threadsafe = false
$ Python setup. py build
$ Sudo Python setup. py install