Go to the python command line and enter importMySQLdb. If no error is reported, it indicates that this module has been installed. Skip the following steps.
Go to the python command line and enter import MySQLdb. If no error is reported, this module has been installed. Skip the following steps.
1. Check whether the MySQLdb module is installed.
Go to the python command line and enter import MySQLdb. If no error is reported, this module has been installed. Skip the following steps.
2. download the latest MySQLdb installation package:
Wget-O python-1.2.3c1.tar.gz
Tar xzvf python-1.2.3c1.tar.gz
Cd MySQL-python-1.2.3c1
3. Go to the MySQLdb source code directory and run python setup. py build.
Error: ImportError: No module named setuptools
Solution: Install setuptools
Wget-O 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 is not found.
Solution:
1) run the whereis mysql command to find the mysql installation directory. Assume that mysql is installed in/usr/local/mysql.
2) return to the MySQLdb source code directory, vi setup_posix.py or vimsetup_posix.py, open the configuration file, find mysql_config.path, and change the path to the bin directory under the mysql installation path, that is, mysql_config.path = "/usr/local/mysql/bin/mysql_config ".
If MySQL is installed in the default system path, the mysql_config script file is located in "/usr/bin/mysql_config ". (If mysql_config is not available, install the mysql-dev package)
Error:/usr/bin/ld: cannot find-lmysqlclient_r
Solution:
Switch to the root user and run echo "/usr/local/mysql/lib/mysql">/etc/ld. so. conf # Please advise this/etc/ld. so. conf. This is the default configuration file of the ld, which varies depending on the system. /Usr/local/mysql/lib/mysql is related to the mysql installation directory.
Force refresh the ld configuration file. Use: ldconfig
Enter the mysql lib directory, for example,/usr/local/mysql/lib/mysql #, which is related to the mysql installation directory.
If libmysqlclient_r.so is not available, a soft connection ln-s libmysqlclient. so libmysqlclient_r.so will be established.
Exit root and switch to the current user.
Error: _ mysql. c: 2810: error: expected declaration specifiers before 'init _ mysql'
Solution: install python-dev and yum install python-devel.
4. Go to the MySQLdb source code directory and run sudo python setup. py install
Read more: Install the MySQLdb module in Linux.