Compile and install the mysql python tutorial under Linux

  • 2020-04-02 14:34:37
  • OfStack

1. Download mysql-python

Website address: (link: http://sourceforge.net/projects/mysql-python/)

2. Install mysql-python


# tar -zxvf MySQL-python-1.2.3.tar.gz
# cd MySQL-python-1.2.3
# whereis mysql_config
mysql_config: /usr/bin/mysql_config /usr/share/man/man1/mysql_config.1.gz
# vi site.cfg
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.1.gz
# export LD_LIBRARY_PATH=/usr/include/mysql
# python setup.py build
# python setup.py install

Note:
1. Mysql header file is required to compile mysql-python.
Setuptools is required to install mysql-python.

3, test,


# python
>>> import MySQLdb
>>>

If there is no error message or the following error message, the installation is successful.

Error:


/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 sys.path

Reasons for error reporting:

Execute python setup.py install, and the MySQLdb module will be copied from python's site-packages directory. If the same module exists in the directory where python is executed, it is possible to import the module repeatedly.

Solutions:

Simply execute python in a different directory.


Related articles: