Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

_mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host

1,993 views
Skip to first unread message

nepaul

unread,
Aug 15, 2012, 9:30:26 AM8/15/12
to
The code:
import MySQLDB
strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'"



_mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root', passwd = '123456', db = 'test', host = 'localhost'' (11004)")


Mark Lawrence

unread,
Aug 15, 2012, 10:23:24 AM8/15/12
to pytho...@python.org
My highly paid team of consultants suggest that you're trying to connect
to a MySQL server host that doesn't exist. However I'm sure that people
on this list with more knowledge of MySQLDB than my consultants will be
able to give you more detailed data.

--
Cheers.

Mark Lawrence.

nepaul

unread,
Aug 15, 2012, 10:53:50 AM8/15/12
to comp.lan...@googlegroups.com, pytho...@python.org
在 2012年8月15日星期三UTC+8下午10时23分24秒,Mark Lawrence写道:
if i use MySQLdb.connect(strCmd) -> wrong, but if use MySQLdb.connect(user = 'root', passwd = '123456', db = 'test', host = 'localhost'),it work. and the strCmd is read from a xml file.

Hans Mulder

unread,
Aug 15, 2012, 11:02:59 AM8/15/12
to
This message means that the MySQL connector cannot find 'localhost'.
That's odd, since localhost should be your own computer.

Which OS are you using? Is TCP/IP installed and enabled?

Can you find an entry for 'localhost' in your /etc/hosts file?
Can you ping it?

What happens if you try host='127.0.0.1'?

Incidentally, connecting as 'root' for non-administrative purposes is
considered bad practice. Consider creating a 'test' account that only
has access to the 'test' database.

Oh, and I hope that '123456' is not really the password for 'root'.


Hope this helps,

-- HansM

nepaul

unread,
Aug 15, 2012, 10:53:50 AM8/15/12
to pytho...@python.org
在 2012年8月15日星期三UTC+8下午10时23分24秒,Mark Lawrence写道:

Alain Ketterlin

unread,
Aug 15, 2012, 11:22:49 AM8/15/12
to
Hans Mulder <han...@xs4all.nl> writes:

> On 15/08/12 15:30:26, nepaul wrote:
>> The code:
>> import MySQLDB
>> strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'"
>>
>>
>>
>> _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root',
>> passwd = '123456', db = 'test', host = 'localhost'' (11004)")
>
> This message means that the MySQL connector cannot find 'localhost'.

No, it means that connect received a single string "user = 'root'..."
instead of a set of individual keyword parameters, and took the whole
string to be the name of the host (its first parameter). Of course,
there is no host with such a name.

The solution is to parse the string into individual values, and pass
these in the correct order.

-- Alain.

nepaul

unread,
Aug 15, 2012, 12:50:34 PM8/15/12
to
在 2012年8月15日星期三UTC+8下午11时22分49秒,Alain Ketterlin写道:
Yeah!Great!Thanks!
Message has been deleted

nepaul

unread,
Aug 15, 2012, 9:52:29 PM8/15/12
to pytho...@python.org
在 2012年8月16日星期四UTC+8上午12时58分07秒,Dennis Lee Bieber写道:
> On Wed, 15 Aug 2012 17:22:49 +0200, Alain Ketterlin
>
> <al...@dpt-info.u-strasbg.fr> declaimed the following in
>
> gmane.comp.python.general:
>
>
>
> > Hans Mulder <han...@xs4all.nl> writes:
>
> >
>
Right!
> MySQLdb code itself recommends to always use keyword parameters, so
>
> the order shouldn't be significant... (and when one sees the list of
>
> optional keywords, using null commas to space positional arguments would
>
> be insane)
>
>
>
> Parsing that string into separate fields (preferably a dictionary so
>
> **conectitems could be used) OTOH is critical.
>
>
>
> --
>
> Wulfraed Dennis Lee Bieber AF6VN
>
> wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/

nepaul

unread,
Aug 15, 2012, 9:52:29 PM8/15/12
to comp.lan...@googlegroups.com, pytho...@python.org
在 2012年8月16日星期四UTC+8上午12时58分07秒,Dennis Lee Bieber写道:
> On Wed, 15 Aug 2012 17:22:49 +0200, Alain Ketterlin
>
> <al...@dpt-info.u-strasbg.fr> declaimed the following in
>
> gmane.comp.python.general:
>
>
>
> > Hans Mulder <han...@xs4all.nl> writes:
>
> >
>
Right!
0 new messages