2

MySQL is running on XAMPP and working fine. I am trying to connect to it through the Windows Subsystem for Linux running a Flask app using flask-msqldb. But when I run the Flask app and try to make a connection (mysql.connection.cursor()) the following error ensues:

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

Is it even possible to make them connect?

1 Answer 1

2

Okay just did some digging around and found this helped:

  • Instead of 'localhost' use the IP address instead Eg:app.config['MYSQL_HOST'] = '127.0.0.1' apparently, clients have some internal aliasing done which results in conflicts. Read:source
  • Add the Flask config setting app.config['MYSQL_UNIX_SOCKET'] = 'TCP' which specifies that the connection is remote.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .