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?


Okay just did some digging around and found this helped:

  • Instead of 'localhost' use the IP address instead Eg:app.config['MYSQL_HOST'] = '' 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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.