Results 1 to 3 of 3

Thread: problem with python and mysql

  1. #1
    Join Date
    Mar 2008
    Beans
    170

    problem with python and mysql

    Hi,

    I'm trying to learn how to access databases using python but I'm having some problems. I've imported MySQLdb but when I run the command

    Code:
    cxn = MySQLdb.connect(user='root')
    I get the error

    Code:
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/var/lib/python-support/python2.5/MySQLdb/__init__.py", line 74, in Connect
        return Connection(*args, **kwargs)
      File "/var/lib/python-support/python2.5/MySQLdb/connections.py", line 170, in __init__
        super(Connection, self).__init__(*args, **kwargs2)
    _mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
    I've found various suggestions but I don't know which to try. Any suggestions would be appreciated. TAI

  2. #2
    Join Date
    Mar 2008
    Beans
    170

    Re: problem with python and mysql

    I don't know why this thread say SOLVED but it is not.

  3. #3
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,699

    Re: problem with python and mysql

    You almost certainly need to supply a passwd parameter as well.
    cxn = MySQLdb.connect(user='root', passwd='whatever')

    Don't forget to COMMIT any database writes, or you will spend many hours wondering why your data doesn't get written to the database. I've been there, got the t-shirt.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •