1. Download mysql-python
Official website address:/projects/mysql-python/
2、Install mysql-python
Copy Code The code is as follows.
# tar -zxvf MySQL-python-1.2.
# cd MySQL-python-1.2.3
# whereis mysql_config
mysql_config: /usr/bin/mysql_config /usr/share/man/man1/mysql_config.
# vi
threadsafe = False
mysql_config = /usr/bin/mysql_config
# whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.
# export LD_LIBRARY_PATH=/usr/include/mysql
# python build
# python install
Caution.
1. Compiling mysql-python requires the mysql header file.
2. The setuptools tool is required to install mysql-python.
3. Testing
Copy Code The code is as follows.
# python
>>> import MySQLdb
>>>
If there is no error message or the following error message, then the installation is successful.
Error message.
Copy Code The code is as follows.
/usr/local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/_mysql.pyc, but /root/MySQL-python-1.2.3 is being added to
Reason for error.
By executing python install, the MySQLdb module is copied to python's site-packages directory. If the same module exists in the directory where python is executed, the module may be imported twice.
Solution.
Just execute python in a different directory.