1

This code works fine:

import MySQLdb
db = MySQLdb.connect("localhost", "root", "","bullsorbit")
cursor = db.cursor()
cursor.execute("Select * from table where conditions'")
numrows = int(cursor.rowcount)
print 'Total number of Pages : %d ' % numrows

but if I give my IP address

db = MySQLdb.connect("192.168.*.*", "root", "","bullsorbit")

it will give this error

super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'ip address' (111)")
Jeremy Stein
19.8k18 gold badges71 silver badges84 bronze badges
asked Jul 22, 2009 at 9:12
1
  • Is your server configured to allow the root to login on a non-localhost connection? Commented Jul 22, 2009 at 9:19

4 Answers 4

5

Code 2003 is a standard MySQL client error:

Error: 2003 (CR_CONN_HOST_ERROR) Message: Can't connect to MySQL server on '%s' (%d)

I'd guess that your user is not allowed to connect to the MySQL server using an iP-address. What happens if you try a connection usign the MySQL commandline client?

$ mysql --host=192.168.1.1 -u root bullsorbit

answered Jul 22, 2009 at 10:17
Sign up to request clarification or add additional context in comments.

2 Comments

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.5.23' (111)
So your problem has nothing to do with Python. You must give the user the permission to connect from the IP address of your local machine.
3

with localhost you connect via loopback-interface.

with ip-addr you connect - as you connect from extern.

if your server allows only the local (loopback) connection your ip-addr connection fails. (security!)

look at your mysql config, maybe only local-connections are allowed.

is the skip-networking switch off (in the mysql-conf) ?

#skip-networking
answered Jul 22, 2009 at 9:18

Comments

1

For the 2003 error, another possibility is that too many connections are being attempted in too short of time. I noticed this same behavior when I had 127.0.0.1 as my connect string. First I replaced it with localhost which got me further but still the same 2003 error. Then I saw that if I scaled back the number of calls the error disappeared completely.

answered Jan 2, 2013 at 16:06

Comments

0

Instead of:

db = MySQLdb.connect("192.168..", "root", "","bullsorbit")

try:

db = MySQLdb.connect(user="root", host="192.168..", db="bullsorbit")

Password will default to empty string and try the usual identity methods. Host will also default to localhost on default port.

answered Jul 22, 2009 at 9:19

1 Comment

hi thank for reply .. i try both i will give same error message

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.