When running a Flask application with Flask-SQLAlchemy, how can I use the MySQL client in the same database at the same time?

When I launch a Flask application that uses Flask-SQLAlchemy, it seems that Flask-SQLAlchemy is conducting a session, and when I issue a MySQL command, for example, to the add column of the change table, in the MySQL client terminal, the commands cannot be executed until I exit Flask applications.

Does anyone have a similar experience? How can I issue commands to the MySQL client without interrupting the Flask application?

+4
source share
1 answer

You might want to look at this question. Alchemy SQL Link Loader leaves a lock on the table?

What you need to do is subclass flask.ext.sqlalchemy.SQLAlchemy and override apply_driver_hacks to pass an additional keyword argument isolation_level='READ <some level>' :

 from flask.ext.sqlalchemy import SQLAlchemy class UnLockedAlchemy(SQLAlchemy): def apply_driver_hacks(self, app, info, options): if not "isolation_level" in options: options["isolation_level"] = "READ COMMITTED" # For example return super(UnLockedAlchemy, self).apply_driver_hacks(app, info, options) 
+6
source

Source: https://habr.com/ru/post/1433740/


All Articles