Flask-MySQL

Flask-MySQL is a Flask extension that allows you to access a MySQL database.

You can report bugs and discuss features on the issues page.

Installation

Use pip to install flask-mysql :

pip install flask-mysql

Configuration

To configure access to your MySQL database server by using these settings :

MYSQL_DATABASE_HOST default is ‘localhost’
MYSQL_DATABASE_PORT default is 3306
MYSQL_DATABASE_USER default is None
MYSQL_DATABASE_PASSWORD default is None
MYSQL_DATABASE_DB default is None
MYSQL_DATABASE_CHARSET default is ‘utf-8’

Usage

Initialize the extension :

from flaskext.mysql import MySQL
mysql = MySQL()
mysql.init_app(app)

Obtain a cursor :

cursor = mysql.get_db().cursor()