How to download and install MySQLdb module for Python on Linux

 

Please use md5 checksum to make sure the downloaded files are not corrupt. Also, $ before commands mean you can run the command as ordinary user and # means you have to run the command as root (or use $ sudo <command>).

$ wget http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
$ tar xzf MySQL-python-1.2.3.tar.gz
$ cd MySQL-python-1.2.3
# /opt/python/bin/python setup.py install

That should install MySQLdb module, but in case you get an error complaining about missing mysql_config, do the following inside MySQLdb unzipped folder (use your favorite text editor instead of nano, if you will):

$ nano site.cfg

and find the line that starts with something like the following:

# mysql_config = ...

You have to uncomment it and replace the path with path of mysql_config in your local machine. On my computer, I did the following:

mysql_config = /opt/mysql/bin/mysql_config

Ctrl-O to save and Ctrl-X to exit out of nano and run the following on command line:

# /opt/python-2.7/bin/python setup.py install

That should install the MySQLdb module for your python installation. To verify:

$ ls /opt/python/lib/python2.7/site-packages/ -la | grep MySQL

The output looked like below on my machine:

-rw-r--r--  1 root root 106932 Nov  4 11:49 MySQL_python-1.2.3-py2.7-linux-x86_64.egg

Please feel free to use the comments form below if you have any questions or need more explanation on anything.

Tags

linux, mysql, install, python, download, module, mysqldb,

Popular Searches

linux, php, mysql mysql, mysql, ubuntu, install mysql, gearman, tools, java, source code

more>>

Comments (write a comment):

0 comments so far. Be the first one to leave a comment on this article.

 

Comment