I am trying to use sqlachemy with bind because I have more than one database. If I go to the bash and execute the command to create tables, it generates the following error:
sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)") (Background on this error at: http://sqlalche.me/e/13/e3q8) During handling of the above exception, another exception occurred:
I tried this sqlachemy:
app.config['SQLALCHEMY_DATABASE_URI'] = f'mysql://<username>:<password>@<username>.mysql.pythonanywhere-services.com/firstdb' app.config['SQLALCHEMY_BINDS'] = { 'variable1': f'mysql://<username>:<password>@<username>.mysql.pythonanywhere-services.com/seconddb', 'variable2': f'mysql://<username>:<password>@<username>.mysql.pythonanywhere-services.com/thirddb', 'variable3': f'mysql://<username>:<password>@<username>.mysql.pythonanywhere-services.com/fourthdb' }
I also tried:
app.config['SQLALCHEMY_DATABASE_URI'] = db.database(dbn = 'mysql', db = '<username>$firstdb', user = '<username>', pw = '<password>', host='<username>.mysql.pythonanywhere-services.com', port=3306)
app.config['SQLALCHEMY_BINDS'] = {
'sbecfrenchhigh': db.database(dbn = 'mysql', db = '<username>$seconddb', user = '<username>', pw = '<password>', host='<username>.mysql.pythonanywhere-services.com', port=3306),
'sbechigharabic': db.database(dbn = 'mysql', db = '<username>$thirddb', user = '<username>', pw = '<password>', host='<username>.mysql.pythonanywhere-services.com', port=3306),
'sbecjunior': db.database(dbn = 'mysql', db = '<username>$fourthdb', user = '<username>', pw = '<password>', host='<username>.mysql.pythonanywhere-services.com', port=3306)
}
but they all failed with the error mentioned above.
from the bath terminal, here is the code I issued:
from myapp import db, create_app db.create_all(app=create_app())
this is because I am using the create_app() function
I have all modules installed but no matter what I do, it does not connect to MySQL. Any help will be highly appreciate. thanks