Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect to MySQL using a connection string #44

Open
idarous opened this issue Sep 19, 2020 · 0 comments
Open

Connect to MySQL using a connection string #44

idarous opened this issue Sep 19, 2020 · 0 comments

Comments

@idarous
Copy link

idarous commented Sep 19, 2020

Hello I'm deploying my application on heroku using ClearDB MySQL.

This platform provides the connection string to the database on an environment variable named CLEARDB_DATABASE_URL that contains a value like that

mysql://username:password@host/databasename?reconnect=true

Is it possible to use directly this string in order to connect my Flask application to this MySQL database without creating a script that parse this string ?

I know that I can specify the configuration like that

from flask import Flask
from flaskext.mysql import MySQL

app = Flask(__name__)
app.config['MYSQL_DATABASE_USER'] = 'username'
app.config['MYSQL_DATABASE_PASSWORD'] = 'password'
app.config['MYSQL_DATABASE_DB'] = 'databasename'
app.config['MYSQL_DATABASE_HOST'] = 'host'
mysql = MySQL()
mysql.init_app(app)

but it will be better for me to be able to specify the configuration like that

from flask import Flask
from flaskext.mysql import MySQL
import os

app = Flask(__name__)
app.config['CONNECTION_STRING'] = os.environ['CLEARDB_DATABASE_URL']
mysql = MySQL()
mysql.init_app(app)

Is it possible to do something like that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant