This article mainly introduces the installation notes in PythonMySQLdbLinux. This article describes two methods: quick installation and manual compilation and installation, and explains the operation steps respectively, if you need it, you can refer to it once in the windows environment at home.
See python MySQLdb quick installation and troubleshooting in windows.
Http://www.bitsCN.com/article/65746.htm
In the company's development needs, another time, under linux.
I found that it was really painful to install it by compiling, but it was just a matter of time and a variety of problems...
There are two methods:
A. quick installation
B. compile it by yourself
1. the fastest and easiest way (in a hurry)
The code is as follows:
Sudo yum install MySQL-python
Possible problems:
The code is as follows:
>>> Import MySQLdb
Traceback (most recent call last ):
File" ", 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
The code is as follows:
Rm-rf Co., MySQL-python-1.2.3/
Proceed
The code is as follows:
>>> 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
The code is as follows:
Wget-O setuptools-0.6c8.tar.gz http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c8.tar.gz
Decompress and run 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.
The code is as follows:
$ 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
The code is as follows:
Threadsafe = False
$ Python setup. py build
$ Sudo python setup. py install
End ~