Kumar Krishnappa Kumar Krishnappa - 30 days ago 15
MySQL Question

django.db.utils.OperationalError: (1045, "Access denied for user 'someuser'@'localhost' (using password: NO)")

I am getting error when try to run


python manage.py migrate


django.db.utils.OperationalError: (1045, "Access denied for user 'someuser'@'localhost' (using password: NO)")

This is my database setting inside setting.py


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': '/config/mysql.cnf',
},
}
}


config/mysql.cnf


[client]
database = dbname
user =
root
password = passwt
host = localhost

default-character-set = utf8


Answer Source

Why not you provide configs directly in settings.py file, as like below

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql', 
    'NAME': 'DB_NAME',
    'USER': 'DB_USER',
    'PASSWORD': 'DB_PASSWORD',
    'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
    'PORT': '3306',
    'OPTIONS': {
        'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
        'charset': 'utf8mb4',
    }
} }

If you need to configure with external file. try this

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'OPTIONS': {
        'read_default_file': os.path.join(BASE_DIR, 'mysql.cnf'),
    }
}

}

The mysql.cnf file should be in project dir