sshussain270
sshussain270

Reputation: 1865

How to open remote MySQL connection at a LAMP(Python) stack

I am developing a django application where my MySQL database is present. My django application and database setup is on one machine.

Now I have 2 other machines running a script which need to remotely connect to my MySQL database present in my main machine.

So in my main machine. I have done this:

sudo nano /etc/mysql/my.cnf

Then changed

bind-address           = 127.0.0.1

to

bind-address           = [my public ip address]

After that, I opened remote access to my database port through my firewall by running:

sudo ufw allow 3306/tcp
sudo service ufw restart

After that, I ran my mysql and ran the following command:

CREATE USER newuser@[main machine ip address] IDENTIFIED BY 'my password';

GRANT ALL PRIVILEGES ON * . * TO newuser@[main machine ip address];

FLUSH PRIVILEGES;

Now when I try to connect to my database remotely from a desktop application using:

username: newuser@[my public ip address]

password: my_password

port: 3306

database: my database name

host: [my public ip address]

It doesn't connect and gives our the error 'access denied'. Is there anything else that I need to do to make it working? Any idea?

UPDATE:

I have tried to connect through command line from my other server to the main server using:

mysql -u newuser -p -h [my main server ip address]

And

mysql -u newuser@[my main server ip address] -p -h [my main server ip address]

It gives me this error: Host '[my local ip address]' is not allowed to connect to this MySQL server

Upvotes: 0

Views: 1019

Answers (1)

Dimi
Dimi

Reputation: 1267

instead of doing machine ip address, allow any host 'user'@'%' and see if it works.

If it does, check the logs to see what your hostname is displayed to your server as.

Changing bind address is not necessary.

Upvotes: 1

Related Questions