0

I am trying to add a database on "https://17x.xxx.xxx.xxx/phpmyadmin/" as my database for my Django project. I have given correct database name, username and password. But I get this error.

After deep investigation I found out that I cant access my database even from the command line or any other external source beside phpmyadmin site

The error that I get is,

django.db.utils.OperationalError: (1130, "Host '19x.xxx.xxx.xxx' is not allowed to connect to this MariaDB server")

I haven't done this before. The database server is not mine. Is there something wrong with the way I've proceeded?

Pabasara Ranathunga
  • 160
  • 1
  • 2
  • 18
  • Which database are you trying to connect? MariaDB or MySql – Niranj Rajasekaran Apr 11 '18 at 07:55
  • As for the error I think it is MariaDB – Pabasara Ranathunga Apr 11 '18 at 07:55
  • Server type: MariaDB – Pabasara Ranathunga Apr 11 '18 at 07:57
  • 2
    Are you able to connect to the database via phpmyadmin / command line – Niranj Rajasekaran Apr 11 '18 at 07:59
  • 1
    The error definitely comes from the DB server. There seems to be a restriction of source addresses your user can connect from. See [this post](https://stackoverflow.com/questions/1559955/host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server) as well – shmee Apr 11 '18 at 07:59
  • @NiranjRajasekaran I haven't tried to connect with the command line, but yes with phpmyadmin i have connected – Pabasara Ranathunga Apr 11 '18 at 08:01
  • As @shmee said there could be restrictions on how many connections is allowed to connect at a time, so try to disconnect from your phpmyadmin and try it once again from django – Niranj Rajasekaran Apr 11 '18 at 08:08
  • I tried using the command line.. the same error appears – Pabasara Ranathunga Apr 11 '18 at 08:09
  • Take a look at this question https://stackoverflow.com/questions/19101243/error-1130-hy000-host-is-not-allowed-to-connect-to-this-mysql-server – shlomta1 Apr 11 '18 at 08:10
  • If you can use PHPMyAdmin you could use that to grant `%` to the user. This should allow that user to connect remotely. You also will need to allow remote connections but this depends how its setup. Are you running this on a server using cPanel or something else? This is probably not a Django issue. – Sam Collins Apr 11 '18 at 08:11
  • @PabasaraRanathunga but connecting via phpmyadmin is not the same as connecting using Django's backend driver. With phpmyadmin, the connection will be made from the server that runs the phpmyadmin page, very likely this is also the server that the DB runs on. If your user was created using `'user'@'localhost'` phpmyadmin will work perfectly while connection attempts form any other source IP will be rejected. You'll need to get that info from an admin on the DB – shmee Apr 11 '18 at 08:11
  • well I tried what was suggested by @shmee and shlomta1 but I still get that error. – Pabasara Ranathunga Apr 11 '18 at 08:21
  • @SamCollins I tried that but no use. yup it seems that this is not a Django issue since the same error occur in the command line. Could you please suggest an edit for my question as this no longer is a Django issue. thanks – Pabasara Ranathunga Apr 11 '18 at 08:41
  • @PabasaraRanathunga I could but then your question would basically be a duplicate of the ones suggested by other users. Without details about how your database server is setup you might not be able to get much more help – Sam Collins Apr 11 '18 at 09:40

1 Answers1

1

Well after several tries I found what was wrong. The problem was that there was no user in the db server for my local IP [private IP]. So I added a new user to phpmyadmin with required privileges and tried again and it worked.

mysql -u {user_name} -p{password} -h {db_host} {db_name}

and I got

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is xxxxxx Server version: 5.5.5-10.1.31-MariaDB MariaDB Serverckquote

Pabasara Ranathunga
  • 160
  • 1
  • 2
  • 18