Tag Archives: mysql

Flask Mysql database connection


How to connect a MySQL database with you Flask python app. MySQL is the most commonly used database today, here is the code

app.config['DATABASE_FILE'] = 'uchat'
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://scott:tiger@localhost/' + app.config['DATABASE_FILE']
app.config['SECRET_KEY'] = '123456790'
app.config['SQLALCHEMY_ECHO'] = True

With MySQL driver called pymysql which is available in Python Package Index  Library, you can connect even local database for development purpose.  To install this package use  pip

Run the following command from your command prompt

pip install pymysql

and pip will download and install necessary packages.