Search code examples
pythonmysqlflasksqlalchemypythonanywhere

Migrating from sqlite to mysql - SQLalchemy


I recently tried to migrate a flask site using a SQLite db connected to using SQLalchemy. I am migrating to Pythonanywhere and I want to change to a mySQl db. I used this code to connect to the db:

mysql+mysqldb://USERNAME:PASSWORD@hanchera1d.mysql.pythonanywhere-services.com/news

obviously I replace USERNAME and PASSWORD with the necessary values. I get this error:

sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1044, "Access denied for user 'USERNAME'@'%' to database 'news'") (Background on this error at: http://sqlalche.me/e/e3q8)

please help, I'm not sure what to do at this point. Thank you


Solution

  • Been playing around with my own account on Pythonanywhere and figured it out. The database name is username$dbname so your connection string should be:

    mysql+mysqldb://USERNAME:PASSWORD@hanchera1d.mysql.pythonanywhere-services.com/USERNAME$news