Safe way to store mysql server credentials in flask? Safe way to store mysql server credentials in flask? flask flask

Safe way to store mysql server credentials in flask?


The computer which runs your code needs to know the password, so you can't secure against the owner of the computer (if that's not you). But if you are having the password in the sourcecode it can easily happen that you put it into version control and if you use a public github it can easily happen that you publish your key.

As alternative you can put the password in a config file (take care to not put it into version control e.g. via .gitignore) or you can use environmental variables.


I would suggest to store the credentials in the OS environment.

app.config['MYSQL_HOST'] = os.environ.get('HOST')app.config['MYSQL_USER'] = os.environ.get('USER')app.config['MYSQL_PASSWORD'] = os.environ.get('PASSWORD')app.config['MYSQL_DB'] = os.environ.get('DB')app.config['MYSQL_CURSORCLASS'] = 'DictCursor'

It will help you to get those information from a standalone application or as a dockerized application (using docker file).