Helpful Information
 
 
Category: Python Programming
Access to a MySQL database

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?

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:


$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.

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

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").

You Right, Since it is the default value.
I tough you connect to it from different machine (?)










privacy (GDPR)