Python MySQL.connect() question

Hafeez Bana hafhat at cs.rmit.edu.au
Mon Jan 31 08:37:00 EST 2000


Try using "127.0.0.1" instead of localhost.

Hafeez

Jim Conger wrote:
> 
> Boudewijn,
> 
> Thanks you for the quick response.  I'm still missing something.  Here is my
> attempt to follow you example.  First I check that mySQL is running using
> mysqladmin, and then attempt to connect in python:
> 
> $ mysqladmin -ppassword processlist
> 
> | Id | User | Host     | db | Command  | Time | State | Info
> | 12 | jimc | localhost |    | Processes | 0 |    |     |
> 
> $ python
> Python 1.5.1...........
> >>> import MySQL;
> >>> self.dbConnection = MySQL.connect("localhost","jimc","password")
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> MySQL.error: Can't connect to local MySQL server
> >>>
> 
> Does mySQL need to be already connected to a DB?  If so how?  I'm sure it is
> obvious, but I can't figure it out!
> 
> Regards,
> Jim Conger
> www.regnoc.com
> 
> Boudewijn Rempt wrote:
> 
> > Jim Conger <jimc at regnoc.com> wrote:
> > > I have mySQL running on a RH Linux 6.1 box, and have added the
> > > MySQLmodule.so to my python library.  I can't figure out how to connect
> > > within python.  My attempts look like:
> >
> > >>>> import MySQL;
> > >>>> db = MySQL.connect();
> > > Traceback (innermost last):
> > >   File "<stdin>", line 1, in ?
> > > MySQL.error: Can't connect to local MySQL server
> > >>>>
> >
> > I'm not really surprised - I think you need to supply
> > some parameters:
> >
> >     hostname="essle"
> >                 username="boud"
> >                 password=""
> >                 databasename="languages"
> >     self.dbConnection = MySQL.connect(hostname,username,password)
> >           self.dbConnection.selectdb(databasename)
> >
> > Which is what I did when I used MySQLmodule; however, I've since
> > began using the DB-API II compliant MySQLdb, but I miss some of
> > the conveniences of MySQLmodule.
> >
> > --
> >
> > Boudewijn Rempt  | http://www.valdyas.org
> 
> --
> Jim Conger
> Project Manager
> Silicon Valley Oil Co.
> jimc at regnoc.com, 925-842-6729



More information about the Python-list mailing list