March 12th, 2013, 04:42 PM
Problems connecting to remote MySQL database via Python script
I am trying to connect to a remote Ubuntu server running MySQL from a Python script but I keep on getting the error "OperationalError: (1130, "Host '192.168.1.2' is not allowed to connect to this MySQL server")"
This is the test script I'm running:
On my server, I have created a new user for this remote machine using the command:
db = MySQLdb.connect(
host = '192.168.0.2',
user = 'james',
passwd = 'toor',
db = 'test'
cursorCardNumber = db.cursor()
cursorCardNumber.execute('SELECT CardNumber FROM testv1')
resultCardNumber = cursorCardNumber.fetchmany()
resultStringCard = str(resultCardNumber)
print ("This is the card number:\n")
for i in resultStringCard:
I think the problem may stem from the 'james'@'winxp' part of the command. I'm using Windows XP with the default administrator login, not connected to a domain with the computer name winxp.
create user 'james'@'winxp' identified by "toor";
grant all privileges on *.* to 'james'@'winxp';
If anyone can steer me in the correct direction, it will be greatly appreciated.
March 13th, 2013, 08:30 AM
Correct, the host name in this command refers to the ip/host name that you _come_from_ and that the MySQL server will see when it performs a _reverse_DNS_lookup_ on the ip-address that your client has (in your case 192.168.1.2) and that name is most probably not winxp.
Unless you are sure that you have DNS properly setup I recommend using the IP-address instead and specially together with a wildcard if your client happen to get another address from the DHCP sometimes.
So in your case I suggest:
create user 'james'@'192.168.1.%' identified by "toor";
March 13th, 2013, 09:26 AM
Thank you for your reply sr. I had a feeling this was completely incorrect and did a bit of research this morning and found that the IP address would be the best option. Naively, I forgot that DNS isn't set up on the network, but that's how your mind works when you've been working on it for ten hours!