sqlacodegen - can't connect to database

956 views Asked by At

I am trying to use sqlacodegen on my database.

sqlacodegen mysql://root:mypassword@localhost/database_name

However, I keep receiving this error:

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

In my flask application however, I access this very same database with no issues.

The above file doesn't exist on my system so I went to /etc/mysql/my.cnf and changed the line:

socket      = /var/run/mysqld/mysqld.sock

to

socket      = /opt/lampp/var/mysql/mysql.sock

Not entirely sure if this was the correct thing to do.. however even after this change, the systems seems to still be trying to run from the original location.

1

There are 1 answers

0
Wowotek On

you can just create a symbolic link at /var/run/mysqld/mysqld.sock to the lampp's mysql sock.

sudo ln -s /opt/lampp/var/mysql/mysql.sock/ /var/run/mysqld/mysqld.sock

restart lampp's mysql

sudo /opt/lampp/lampp stopmysql
sudo /opt/lampp/lampp startmysql