GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • flask-mysql

This view

  • Original page
  • New address

GeezerVison is showing flask-mysql.readthedocs.io — Flask-MySQL — flask-mysql 1.6.0 documentation

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()

Multiple connection example:

from flaskext.mysql import MySQL

my_database = MySQL(app, prefix="my_database", host="hostname, user="username", password="password", db="my_database", autocommit=True)
our_database = MySQL(app, prefix="our_database", host="hostname, user="username", password="password", db="our_database", autocommit=True, cursorclass=pymysql.cursors.DictCursor)

@app.route('/')
@app.route('/index')
def hello():
    my_cursor = my_database.get_db().cursor()
    #...
    our_cursor = our_database.get_db().cursor()
    #...
©2012, Timothée Peignier. | Powered by Sphinx 8.1.3 & Alabaster 1.0.0 | Page source
You are visitor 01402622 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.