#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Posts
    0
    Rep Power
    0

    Question


    I tried to get access to a MySQL database like this:

    import MySQLdb

    db = MySQLdb.connect(db = 'mydb', user = 'user', passwd = 'password')

    I get this error:
    Traceback (most recent call last):
    File "Myfile.py", line 3, in ?
    db = MySQLdb.connect(db = 'mydb', user = 'user', passwd = 'password')
    File "/usr/local/lib/python1.6/site-packages/MySQLdb.py", line 457, in __init__
    i = map(int, split(split(self._server_info, '-')[0], '.'))
    ValueError: invalid literal for int(): 26a

    What is wrong?

    Comments on this post

    • BaronVonDoppleG agrees
  2. #2
  3. No Profile Picture
    PerlGuy
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2001
    Posts
    720
    Rep Power
    42
    I don't know much Python, and any database work I've done has been with Perl. However, it doesn't look like you specified a host name as an argument in your connect.

    In Perl with DBI the connect would look like:
    Code:
    $dbh = DBI->connect( "DBI:mysql:database:hostname", "user", "pass", {additional arg} );
    In this connect a hostname would always have to be specified, even if its just 'localhost'.

    Hope this helps.

    Comments on this post

    • BaronVonDoppleG agrees
    - dsb -
    Perl Guy
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Indonesia
    Posts
    0
    Rep Power
    0

    Smile


    You are forgetting one important thing:
    Where is host information you want to connect?

    Comments on this post

    • BaronVonDoppleG agrees
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Posts
    0
    Rep Power
    0
    The problem is already solved. For your information:
    You don't need to specify a host if the DB and the script are on the same machine("local host").
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Indonesia
    Posts
    0
    Rep Power
    0
    You Right, Since it is the default value.
    I tough you connect to it from different machine (?)

IMN logo majestic logo threadwatch logo seochat tools logo