Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQLdb error 1130: Not getting the correct IP of the server [duplicate]

I'm trying to connect to mysqldb through a python script. I have changed the bind-address in my.cnf to '192.168.56.101' which is my server ip.

import MySQLdb

db = MySQLdb.connect(host='192.168.56.101',
                     user='root',
                     passwd='pass',
                     db='python')

the above code gives me following error.

_mysql_exceptions.OperationalError: (1130, "Host '192.168.56.1' is not allowed to connect to this MySQL server")

It has taken my ip '192.168.56.101' as '192.168.56.1'? Also I tried this:

mysql -u nilani -p pass -h 192.168.56.101

It also giving the same kind of error,

ERROR 1130 (HY000): Host '192.168.56.1' is not allowed to connect to this MySQL serve

Why it cannot identify my ip correctly?

like image 840
Nilani Algiriyage Avatar asked Jul 19 '13 16:07

Nilani Algiriyage


1 Answers

This is a lack of permissions on the server side.

MySQL doesn't allow root users to connect from other machines on the network. the IP 192.168.56.1 is probably your own machine's IP.

In order to create a user that can log from other machines, refer to this question: Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server

It involves creating a separate user for localhost and remote host access on the server (taken from linked question):

mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
    ->     WITH GRANT OPTION;
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
    ->     WITH GRANT OPTION;
like image 134
paolobueno Avatar answered Oct 24 '22 02:10

paolobueno