0

There are literally tons of answers, which involve installing mysql-server in ubuntu. But I am using XAMPP and I am able to access mysql server through browser. I want the convenience of both PHPmyadmin and xampp and running flask app from terminal. For some reason, it is giving me the error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock.

I am extremely new to ubuntu and I will grateful if someone tells me how to link xampp mysql server to ubuntu terminal. I simply could not find an answer for this particular answer. My mysql.sock file is in /opt/lammp/var/mysql/ folder, if that helps.

Any help regarding this really appreciated.

EDIT: I have added the following lines my /etc/mysql/my.cnf file:

[mysqld]
 
socket=/opt/lampp/var/mysql/mysql.sock 
 
[client]
 
socket=/opt/lampp/var/mysql/mysql.sock  

But the error message is not changing.

EDIT: This error seems to be only occurring in flask application with the library flask-mysqldb. mysql-connector in python is functioning as expected.

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
lokit khemka
  • 349
  • 3
  • 11
  • It looks like this is mostly answered in [Using MySQL in Flask](https://stackoverflow.com/questions/9845102/using-mysql-in-flask) – Isaac Bennetch Nov 28 '21 at 15:03

1 Answers1

2

You'll apparently have to tell flask the proper path to the socket file (/opt/lampp/var/mysql/mysql.sock, as you know; currently it seems to be looking at /var/run/mysqld/mysqld.sock).

According to the documentation, you'll need to use the MYSQL_UNIX_SOCKET configuration directive along with your other directives for setting things like the username, password, etc, such as app.config['MYSQL_UNIX_SOCKET'] = '/opt/lampp/var/mysql/mysql.sock'.

This answer should point you in the right direction.

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43