Operational Error in Django: Migrating a Python Web Application to a mariadb database

I am trying to connect a mariadb database that I created in a Linux VM and have my python web application migrate the files over.

When I use the python manage.py migrate command, I come across this error:

django.db.utils.OperationalError: (2002, "Can't connect to server on '127.0.0.1' (36)")

When connecting to the database in my terminal, I end up with this error:

mysql -h '127.0.0.1' -P user database_name

ERROR 2002 (HY000): Can't connect to server on '127.0.0.1' (36)

I'm trying to connect via unix_socket, and have already routed the file to the correct path in my my.cnf file. (/tmp/mysql.sock) is not correct and I'm not entirely sure why it designates that as the path outright.

Here is my DATABASES section in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '127.0.0.1',
        'NAME': 'Database-name',
        'USER': 'user',
        'PASSWORD': 'Password',
    }   
}

I've also included an options parameter under 'PASSWORD' to specify where the actual path for my socket file is. Here is my my.cnf file In linux:

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
socket=/var/lib/mysql/mysql.sock
port=3306
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d


I have the port included in the file as well, and tried to see if connecting via the port would work but I get a similar error.

I'm still learning SQL and how databases are configured, I've tried referring to documentation in mariadb and couldn't find an answer to my problem. I'm currently running a CentOS9 VM through UTM.

I have tried changing the host as 'localhost' and signing in that way, but I get similar errors on the command line and in terminal:

Command Line: django.db.utils.OperationalError: (2002, "Can't connect to local server through socket '/tmp/mysql.sock' (2)") 

Terminal: mysql -h localhost -u user databasename OUTPUT: ERROR 2002 (HY000): Can't connect to local server through socket '/tmp/mysql.sock' (2)

I thought it may have to do with the firewall settings in linux, but after checking they are all configured correctly with port 3306 available.

Ive tried restarting the server in mariadb multiple times, but still receive the same error as well. Here is my status of my mariadb when its activated:

mariadb.service - MariaDB 10.11 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; preset: disabled)
     Active: active (running) since Fri 2024-02-23 08:05:28 EST; 5s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 87666 ExecStartPre=/usr/libexec/mariadb-check-socket (code=exited, status=0/SUCCESS)
    Process: 87688 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir mariadb.service (code=exited,>
    Process: 87734 ExecStartPost=/usr/libexec/mariadb-check-upgrade (code=exited, status=0/SUCCES>
   Main PID: 87723 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 11 (limit: 22581)
     Memory: 78.3M
        CPU: 755ms
     CGroup: /system.slice/mariadb.service
             └─87723 /usr/libexec/mariadbd --basedir=/usr

Feb 23 08:05:27 localhost.localdomain systemd[1]: Starting MariaDB 10.11 database server...
Feb 23 08:05:27 localhost.localdomain mariadb-prepare-db-dir[87688]: Database MariaDB is probably>
Feb 23 08:05:27 localhost.localdomain mariadb-prepare-db-dir[87688]: If this is not the case, mak>
Feb 23 08:05:28 localhost.localdomain systemd[1]: Started MariaDB 10.11 database server.
Back to Top