Forums

sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"

Hi guys,

I have two apps that run on different repos, but should link to the same . My first one works fine. The configuration for the is the following:

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://[user]:[password]@[user].mysql.pythonanywhere-services.com/[db]'

On the second app, when I try to"" the app I this error that I can't fix:

sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (2002, "Can't connect to local MySQL server through '/var/run/mysqld/mysqld.sock' (2)"

In my console I can do something like:

from server import app, db
from model import User
User.query.all()

Also, my second app works on a virtual environment, my first app does not. *EDIT: the new tables the second app should create are actually created, I can find them with mysql commands. It is just when I click on "reload" that it gets stuck.

Thanks for your time!

Alright I finally managed to solve it!

I went from

[user].mysql.pythonanywhere-services.com

to

mysql.server

and it worked!

username.mysql.pythonanywhere-services.com should work.

mysql.server is deprecated, so that doesn't sound like a good long-term solution... from the error message, it sounds like sqlalchemy was trying to talk to the local socket, so it was ignoring or not recognising the hostname part of the connection string. Is it possible there was some kind of typo?

I am also facing this same issue and I can't fix it by changing to mysql.server. can anyone help?

We need more details to help you. Write to support@pythonanywhere.com if you do not want to post details on public forums.