I've been working for several weeks on Django. So far I have made 2 small projects. Now I tried to connect Django to the MySQL database.
- First, I started a new project.
- Then made a new app and updated the app in settings.py.
- After that I changed the database in the same file settings.py with my settings.
- Made a small model (in the file models.py).
- Installed all the necessary apps, (pip install) mysqlclient etc,
- Made the first migration successfully with
python manage.py makemigrationsSo far so good!
Next, I tried to make the second migration (python manage.py migrate), as in the instructions.
Then the error message appears:
'error 111, can't connect to database'
Made some changes in the settings file, including SQL mode strict_trans_tables.
Now it shows me the error:
Can't connect to local MySQL server through socket ... Missing file .../mysql.sock.
I looked up the directory and there was no such file.
In the file my.cnf the filename and path is different!!! And exists! (It is using this existing file in my.cnf, but after executing the commang migrate it is searching for this file in a place, where it does not exist!)
To clarify things a little bit, the exact message of the error:
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
There is no such file in the current directory (as I have checked).
my.cnf file contains the following path and filename:
socket=/opt/lampp/var/mysql/mysql.sock
There is a file in the current directory. MySQL works, as well.
What is going on and what to do?