Unable to connect from django to mysql database

I have created the database on XAMPP mysql which is up and running. MySQL up and running The database is created,

djangoproject database

I am now trying to connect from django with the following connection parameters,

DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': "djangoproject",
            'USER': 'root',
            'PASSWORD': '******',
            'HOST': 'localhost',
            'PORT': ''
        }
    }

I am getting the following error when executing python3 manage.py runserver and python3 manage.py migrate

django.db.utils.OperationalError: (1049, "Unknown database 'djangoproject'")

I have read a solution to create the database from mysql shell using the create database statement. My question is why i am not able to connect to the database already created on XAMPP mysql.

1 answer

  • answered 2018-11-08 07:14 Giorgos Myrianthous

    You've missed the port. By default, MySQL is listening to 3306:

    DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.mysql',
                'NAME': "djangoproject",
                'USER': 'root',
                'PASSWORD': '******',
                'HOST': 'localhost',
                'PORT': '3306'
            }
        }