0👍
Finally the Django project was able to start using the MySQL database!!!
The changes in the file setting.py are the same as before, as follows:
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_db',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
the only thing that had to be done in addition to this, was to include the path of file my.cnf manually:
'OPTIONS': {
'read_default_file': '/opt/lampp/etc/my.cnf',
},
Obviously, this was the reason in the first place the path to the socket file to be mistaken.
But why in the first place this error occurs, I don’t know. Perhaps somewhere after the installation some other path was given, but I don’t know where is this path, pointing to other directory of the socket file separately, or to other path for the my.cnf file.
With the PostgreSQL database the connection was made so simply, it required only the 1st changes in the settings.py file.
After that, additional migrations were made without any disturbance, as well as the superuser account.
The source website from which I was able to use as a cheat sheet for the complete process:
https://www.digitalocean.com/community/tutorials/how-to-create-a-django-app-and-connect-it-to-a-database
1👍
You have reached an issue which suggests a MySQL problem. It is wise to try and connect to MySQL directly at this point, because if that’s successful, then you know for sure that your issues are on the application settings’ side and if it’s unsuccessful, then you need to solve MySQL’s connectivity first and only then switch to your app’s settings.
Now, the error clearly suggests that MySQL’s socket file cannot be found.
First, let’s check whether MySQL is running at all. In Ubuntu Linux the command to do so is
sudo service mysql status
If you use something else as an OS, then of course you will need to operate slightly differently.
In Ubuntu, if the command above yields something like
Unit mysql.service could not be found.
, then the service does not exist and you need to install it.
Otherwise, if the service exists but is not running, then you will need to start it if you are able. If not, then you have some maintenance to do.
Finally, if the MySQL service is successfully running, try connecting to it via cli, like:
mysql -u <youruser> -p
The -p
at the end signifies that a password will be used, so after running the command above you will need to type in the password (if everything goes well).
If you get the same socket file-related error (which presumably will happen), then you will need to find the location of the socket file (.sock) and update MySQL’s cnf file (/etc/my.cnf in Linux) so that it will take into account the correct location of the socket file:
socket=/var/lib/mysql/mysql.sock