tags:

views:

345

answers:

4

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)")
+3  A: 

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
Blauohr
+1  A: 

Is your server configured to allow the root to login on a non-localhost connection?

Stephen Edmonds
A: 

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.

bvmou
hi thank for reply .. i try both i will give same error message
+2  A: 

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

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.
thank u ... lot .....