1. See if the MYSQLDB module is installed
Enter the command line of Python, enter import mysqldb if there is no error, prove that the module has been installed, you can skip the following steps.
2. Download the latest MYSQLDB installation package:
Wget-o python-1.2.3c1.tar.gz http://cdnetworks-kr-1.dl.sourceforge.net/project/mysql-python/mysql-python-test/ 1.2.3c1/mysql-python-1.2.3c1.tar.gz
Tar xzvf python-1.2.3c1.tar.gz
CD MYSQL-PYTHON-1.2.3C1
3, enter the user mysqldb source directory, run Python setup.py build.
Error: Importerror:no module named Setuptools
FIX: Install Setuptools
Wget-o setuptools-0.6c8.tar.gz http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c8.tar.gz
Tar xzvf setuptools-0.6c8.tar.gz
CD SETUPTOOLS-0.6C8
Python setup.py Build
sudo python setup.py install
Error: Mysql_config not found
Cause: The Mysql_config command was not found.
Solve:
1) Use the Whereis MySQL command to find the MySQL installation directory, assuming that MySQL is installed in/usr/local/mysql
2) go back to the MySQLdb source directory, vi setup_posix.py or vimsetup_posix.py open the configuration file, find the Mysql_config.path line, change the path to the MySQL installation path under the Bin directory, that is Mysql_ Config.path = "/usr/local/mysql/bin/mysql_config".
If MySQL is installed under the system default path, the Mysql_config script file is located in "/usr/bin/mysql_config". (If there is no mysql_config, you need to install the Mysql-dev package)
Error:/usr/bin/ld:cannot Find-lmysqlclient_r
Solve:
Switch to root user, perform echo "/usr/local/mysql/lib/mysql" >>/etc/ld.so.conf# please mind this/etc/ld.so.conf, this is the LD's default profile, depending on the system and different. The/usr/local/mysql/lib/mysql is related to the MySQL installation directory.
Forces the configuration file for the LD to be refreshed. Use: Ldconfig
Enter the MySQL Lib directory such as/usr/local/mysql/lib/mysql #与mysql安装目录相关.
If there is no libmysqlclient_r.so, establish a soft connection ln-s libmysqlclient.so libmysqlclient_r.so
Exit root and switch to the current user.
Error: _mysql.c:2810:error:expected declaration specifiers before ' Init_mysql '
FIX: Install Python-dev,yum installation Python-devel
4, enter the user mysqldb source directory, run sudo python setup.py install
Installing the MYSQLDB module under Linux