[Ilugc] MySQL and Python connection error

Vannia Rajan kvanniarajan at gmail.com
Fri Jul 17 23:45:21 IST 2009


On Fri, Jul 17, 2009 at 11:24 PM, Raji Seetharaman <sraji.me at gmail.com>wrote:

> I need to connect MySQL database with python
> scripts. First i checked whether MySQLdb is already installed by issuing
> the
> following command from a python shell as
> >>> import mysql
> i got the reply from the shell as
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> ImportError: No module named mysql
> >>>
>

Using mysqldb from python code could be like (you can find many examples
online like this):

(case-sensitive)
>>> import MySQLdb
>>> conn = MySQLdb.connect('localhost', 'root', 'password', 'database_name')
>>> cur = conn.cursor()
>>> cur.execute("your sql queries")


>   Download a recent version from the project
> homepage<http://sourceforge.net/projects/mysql-python>
>          From the first instruction i downloaded MySQL for python inside
> view all files option
>          MySQL-python-1.2.3c1.tar.gz.<
> http://sourceforge.net/projects/mysql-python/files/mysql-python-test/MySQL-python-1.2.3c1.tar.gz/download
> >
>          Extracted the files
>
>     2. Performed the following from a shell (unix) :
>              $ cd MySQL-python-1.2.3c1
>              $ python setup.py build
>
>          i got the following error
>
>              Traceback (most recent call last):
>                    File "setup.py", line 5, in <module>
>                         from setuptools import setup, Extension
>                ImportError: No module named setuptools
>
> What should i do to overcome this error?Help me
>

For installing MySQLdb,

 if you are using debian/ubuntu-based system :
       sudo apt-get install python-mysqldb

 if you are using redhat/fedora-based system:
       sudo yum install MySQL-python

 if any other distributions,
    (i) First download the setuptools python package, install it
    (ii) Then repeat the procedure you have followed

Note:
  python-mailing list would be a better place to post your python-queries :
  http://mail.python.org/mailman/listinfo/python-list

-- 
Thanks,
Vanniarajan


More information about the ilugc mailing list