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:
"SQLALCHEMY_DATABASE_URI": "mysql+pymysql://user:password@localhost/database"
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 tutorial I am following says to set the bind-address found in the mysqld.cnf file to 0.0.0.0:
bind-address = 0.0.0.0
However, doing so breaks the connection from the website with the database. This is the error found in the log:
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query') [SQL: ...]
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?
Although I'm not sure how this helps, I have enabled the connection to the database in the AWS security group rules:
Any help or references regarding my problem are much appreciated. Stay safe!
The mysql configuration can be left as it is. The access protocols are already defined in AWS. What I was missing was configuring a remote user for the database, with '%' as host (which means any host is OK). Then I just entered the DB connection credentials in DBeaver, and it worked!
I am not sure how secure the connection is. Leaving the user open to any connection is probably risky. However, I am not well-read in the matter and can't assess its security status. An SSL connection may be more secure, but I don't know how to configure it.