#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    49
    Rep Power
    0

    Error -Setting up Mysql for Python


    Hey all,

    I installed, the MySQL Server 4.1 and also installed the Python 2.3.4, and the downloaded the MySQL - Python module
    for 2.3 version of python from
    http://prdownloads.sourceforge.net/mysql-python/MySQL-python.exe-0.9.2.win32-py2.3.exe?use_mirror=voxel

    but when i get into the command prompt of python and type
    >>> mySQLdb

    Traceback (most recent call last):
    File "<pyshell#1>", line 1, in -toplevel-
    MySQLdb
    NameError: name 'MySQLdb' is not defined

    I dont know what is the error coming for, let me know what should i do

    Thanz
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    I'm not sure why you are just typing mySQLdb, that module isn't built into Python so that is why you are getting that error. Just type import mySQLdb. If I were to type socket into the Python Interpreter, I would get:
    Code:
    >>> socket
    Traceback (most recent call last):
      File "<pyshell#3>", line 1, in ?
        socket
    NameError: name 'socket' is not defined
    However if I typed in time, I would get:
    Code:
    >>> time
    <module 'time' (built-in)>
    This is because the time module is built into Python, the socket module isn't, and neither is the mySQLdl module. If I'm wrong in saying this, please tell me the purpose in typing mySQLdb into the Interpreter, I've never used the module before so I'm not sure if there is a reason for that.
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You're getting this error because the MySQLdb module isn't located anywhere on the $PYTHONPATH variable; so Python can't find it. This might happen if you selected a custom installation directory for instance.

    If you're on Windows then uninstall the module and install the module in the default directory (site-packages).

    If you're running *nix then you can safely move the module your site-packages folders using the mv command. The location of the site-packages folder will vary depending on where Python is installed .

    Let me know if you have any problems,

    Hope this helps.

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69

    import-ant


    Yegg: the socket module is does come as part of Pythons Standard Library. The reason that you get the error in your program is because you haven't imported it yet. However the error is the same .

    You're right that the MySQLdb module isn't however as sha' said he has downloaded the module form sourceforge.

    Sha': you also need to import the MySQLdb module before you can use it. This could also be the cause your problem.

    Code:
    >>> import MySQLdb
    ...
    Take a look at the MySQL article in Devsheds Python section.

    Take care,

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Ya, that's kind of where I was heading, I just didn't really word it correctly.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    49
    Rep Power
    0
    Hey Thank,s

    I forgot to import, it works,
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    49
    Rep Power
    0
    Hi guys , when everything is setup ,

    I get new errors, During setup of MySQL Server i gave the password as abcdef

    i can run the sql server from command prompt using this password

    but when i use the python code





    #!C:\Python24\Python.exe
    # import MySQL module
    import MySQLdb
    # connect
    db = MySQLdb.connect(host="localhost", user="root",passwd="abcdef",db="test")
    # create a cursor
    cursor = db.cursor()
    # execute SQL statement
    cursor.execute("SELECT * FROM example1")
    # get the resultset as a tuple
    result = cursor.fetchall()
    # iterate through resultset
    for record in result:
    print record[0] , "-->", record[1]





    Traceback (most recent call last):
    File "C:\Documents and Settings\Arpan Shah\Desktop\Ex.py", line 5, in -toplevel-
    db = MySQLdb.connect(host="localhost", user="Arpan",passwd="abcdef",db="test")
    File "C:\Python23\Lib\site-packages\MySQLdb\__init__.py", line 63, in Connect
    return apply(Connection, args, kwargs)
    File "C:\Python23\Lib\site-packages\MySQLdb\connections.py", line 115, in __init__
    self._make_connection(args, kwargs2)
    File "C:\Python23\Lib\site-packages\MySQLdb\connections.py", line 41, in _make_connection
    apply(super(ConnectionBase, self).__init__, args, kwargs)
    OperationalError: (1045, "Access denied for user 'Arpan'@'localhost' (using password: YES)")
    >>> ================================ RESTART ================================
    >>>

    Traceback (most recent call last):
    File "C:\Documents and Settings\Arpan Shah\Desktop\Ex.py", line 5, in -toplevel-
    db = MySQLdb.connect(host="localhost", user="root",passwd="abcdef",db="test")
    File "C:\Python23\Lib\site-packages\MySQLdb\__init__.py", line 63, in Connect
    return apply(Connection, args, kwargs)
    File "C:\Python23\Lib\site-packages\MySQLdb\connections.py", line 115, in __init__
    self._make_connection(args, kwargs2)
    File "C:\Python23\Lib\site-packages\MySQLdb\connections.py", line 41, in _make_connection
    apply(super(ConnectionBase, self).__init__, args, kwargs)
    OperationalError: (1251, 'Client does not support authentication protocol requested by server; consider upgrading MySQL client')
    >>>

    I have no idea to solve this, why its coming, please tell me a step by step procedure which will enable my python code to talk to MySQL Ser.

    thanz
  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    The error looks to be because of an incompatability between MySQL and Pythons MySQLdb module. What versions of these two are you using?

    Edit: I was wrong on this one as simon explains, check out this thread http://forums.devshed.com/t237969/s.html

    Mark.
    Last edited by netytan; March 20th, 2005 at 05:04 PM.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo