I have two databases say xyz and abc. The thing is I want to have two MySQL instances using one Flask app. This is how I initialize one MySQL Instance:
app = Flask(__name__)
app.config['MYSQL_HOST']='localhost'
app.config['MYSQL_USER']='root'
app.config['MYSQL_PASSWORD']='abcd'
app.config['MYSQL_DB'] = 'xyz'
mysql_xyz = MySQL(app)
I have another database lets say 'abc' when I am trying to overwrite 'MYSQL_DB' by:
app.config['MYSQL_DB'] = 'abc'
mysql_abc = MySQL(app)
I am getting the following error:
Debugging middleware caught exception in streamed response at a point where response headers were already sent. MySQLdb._exceptions.OperationalError: (2006, '')
However, another alternative is to create a different app altogether under the same script file app.py
app1 = Flask(__name__)
app1.config['MYSQL_HOST']='localhost'
app1.config['MYSQL_USER']='root'
app1.config['MYSQL_PASSWORD']='abcd'
app1.config['MYSQL_DB'] = 'abc'
mysql_abc = MySQL(app1)
and this works fine. can anyone please let me know how can I overwrite the value of 'MYSQL_DB' config and create another mysql instance using only one app variable.