1

I am developing a project based on Django and MySQL on Ubuntu. I am a little confused about how MySQL should be installed. Should it be installed into the virtual environment or should it be installed into the system:

(a) To install MySQL in the virtual environment (python2Venv is the directory of the virtual environment):

$ sudo apt-get install libmysqlclient-dev
$ source <python2Venv>/bin/activate
(python2Venv)$ pip install MySQL-python

(b) However, according to the installation guide about MySQL, I have to do (https://help.ubuntu.com/12.04/serverguide/mysql.html):

$ sudo apt-get install mysql-python
$ sudo apt-get install mysql-server

Questions:

Is the above steps correct? Are both (a) and (b) necessary, or one of them is enough (maybe with additional setups)?

Randy Tang
  • 4,283
  • 12
  • 54
  • 112

3 Answers3

3

Fisrt, there is no mysql-python under Ubuntu/Debian repositories, the package is python-mysqldb and is an interface to the Mysql Server for python, is the driver for python and is needed to your Django project to work with Mysql. Under pypi repository is named MySQL-python

Second, there is no reason to install a Mysql Server in a Python virtualenv, the Python virtualenv is for Python libraries/modules/frameworks, Mysql Server is not that.

So you can install the Mysql Server in your Ubuntu system by the official repository apt-get install mysql-server

And then you can install all that python libraries that you need in your special python virtualenv for your Django project.

source ~/.virtualenv/<project-name>/bin/activate

pip install Django

pip install MySQL-python

elmonkeylp
  • 2,674
  • 1
  • 16
  • 14
1

to install mysql server:

sudo apt-get install mysql-server

now to install mysql-python in virtual env:

pip install MySQL-python

note: both pip install MySQL-python & apt-get install python-mysqldb are same.

suhailvs
  • 20,182
  • 14
  • 100
  • 98
  • 1
    >note: both pip install MySQL-python & apt-get install mysql-python are same. I don't think so, because both come from different sources, there may be differences between versions – elmonkeylp Sep 20 '14 at 03:18
0

MySQL driver for Python (mysql-python) needs libmysqlclient-dev. You can get it with:

sudo apt-get update
sudo apt-get install libmysqlclient-dev

If python-dev is not installed, you may have to install it too:

sudo apt-get install python-dev

Now you can install MySQL driver:

pip install mysql-python

Here is a complete installation guide for setting up Django to use MySQL on a virtualenv:

http://codex.themedelta.com/how-to-install-django-with-mysql-in-a-virtualenv-on-linux/

Sibi M
  • 31
  • 5