Hugo
Hugo

Reputation: 1698

How can I connect a Jupyter Notebook to a remote MySQL DB using Peewee?

I am trying Peewee to connect and retrieve data from a MySQL remote database, but I get the following error:

InternalError: (1130, "Host 'x.x.x.x' is not allowed to connect to this MariaDB server")

Could you help me?

Upvotes: 1

Views: 2366

Answers (1)

Blag
Blag

Reputation: 5894

"retrieve data from a MySQL remote database"

"Host is not allowed to connect to this MariaDB server"

Seem to point on a simple problem:

You're not allowed to connect on the DB from "outside".


By default, MySql / MariaDB are only listening on the "inside" of the server, from MariaDb doc :

MariaDB packages bind MariaDB to 127.0.0.1 (the loopback IP address) by default as a security measure using the bind-address configuration directive.

This mean apart for an application that run on the same machine (accessing 127.0.0.1 or localhost), you'll not be able to connect.


Solutions:

SSH tunnelling

This is probably the safest way to allow a connexion on a remote DB.

SSH is a protocol that allow you to connect to a server. It's mainly used on unix server to manage them, but can do a lot more.

How to use it in your case?

if you can connect with SSH to your DB server, then running this simple command on your notebook the will do the trick:

ssh -L 3306:localhost:3306 [email protected]

Lets explain a bit: first, your run SSH, then, you tell him to enable a port forwarding from your 3306 port to the localhost:3306 port of the server you connect through user@IP.

With this command running, every query from your local machine:3306 will by send to your MariaDB:3306 server, allowing you to use it as if you where on the server.

Allowing a remote-access user

This one is way more dangerous than the previous one. You'll need to take your time and think about every outcome it mean.

As already said, you're not allowed to connect from outside, ssh let you be "inside", but if you know what you do, you can just remove the security.

The point is:

  • to make an account that'll be able to login from a remote IP,
  • allow MariaDB to listen on external requests,
  • and at least, secure other account to disable remote connection.

[I'm not putting the how-to now, if you really need it, I'll update this answer]

Upvotes: 1

Related Questions