title: Connect to MySQL DB hosted in an AWS EC2 server
body: <p>I have developed a website with Flask, a python framework, deployed with nginx, which works fine. The website interacts with a MySQL database through pymysql and SQLAlchemy using the following URI:</p>
  
  <pre><code>"SQLALCHEMY_DATABASE_URI": "mysql+pymysql://user:password@localhost/database"
  </code></pre>
  
  <p>Both the website and the database are hosted in an AWS EC2 server. I am trying to access that database from my personal computer, establishing a connection with DBeaver. The <a href="https://www.techrepublic.com/article/how-to-set-up-mysql-for-remote-access-on-ubuntu-server-16-04/" rel="nofollow noreferrer">tutorial</a> I am following says to set the bind-address found in the <em>mysqld.cnf</em> file to 0.0.0.0:</p>
  
  <pre><code>bind-address = 0.0.0.0
  </code></pre>
  
  <p>However, doing so breaks the connection from the website with the database. This is the error found in the log:</p>
  
  <pre><code>sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query') [SQL: ...]
  </code></pre>
  
  <p>Thus, I can't set the bind-address. The website works again when I comment it out. How can I keep the website working while allowing the remote access to the database?</p>
  
  <p>Although I'm not sure how this helps, I have enabled the connection to the database in the AWS security group rules:</p>
  
  <p><a href="https://i.stack.imgur.com/uwjiG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uwjiG.png" alt="enter image description here"></a></p>
  
  <p>Any help or references regarding my problem are much appreciated. Stay safe!</p>