How to open remote MySQL connection at a LAMP(Python) stack
<p>I am developing a django application where my MySQL database is present.
My django application and database setup is on one machine.</p>

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

<p>So in my main machine. I have done this:</p>

<pre><code>sudo nano /etc/mysql/my.cnf
</code></pre>

<p>Then changed </p>

<pre><code>bind-address           = 127.0.0.1
</code></pre>

<p>to</p>

<pre><code>bind-address           = [my public ip address]
</code></pre>

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

<pre><code>sudo ufw allow 3306/tcp
sudo service ufw restart
</code></pre>

<p>After that, I ran my mysql and ran the following command:</p>

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

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

FLUSH PRIVILEGES;
</code></pre>

<p>Now when I try to connect to my database remotely from a desktop application using:</p>

<p>username: newuser@[my public ip address] </p>

<p>password: my_password </p>

<p>port: 3306 </p>

<p>database: my database name </p>

<p>host: [my public ip address]</p>

<p>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?</p>

<p><strong>UPDATE:</strong></p>

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

<p><code>mysql -u newuser -p -h [my main server ip address</code>]</p>

<p>And</p>

<pre><code>mysql -u newuser@[my main server ip address] -p -h [my main server ip address]
</code></pre>

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

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

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

<p>Changing bind address is not necessary. </p>

python mysql linux django database