On Thu, Jan 14, 2016 at 4:11 AM, Galil <il...@ajenta.net> wrote: > I have created a Django app and which uses MySQL. The settings.py file in > the database sections is: > > DATABASES = { > 'cdraccess': { > 'ENGINE': 'django.db.backends.mysql', > 'NAME': os.environ.get('CDR_DB_NAME', 'portal2'), > 'USER': os.environ.get('CDR_DB_USER', 'cdraccess'), > 'HOST': os.environ.get('CDR_DB_HOST', '127.0.0.1'), > 'CONN_MAX_AGE': 0, > 'PASSWORD': os.environ.get('CDR_DB_PASSWORD', ''), > }, > 'default': { > 'ENGINE': 'django.db.backends.sqlite3', > 'NAME': 'db.sqlite3', > }} > > I run the app like: > > CDR_DB_PASSWORD='password' CDR_DB_HOST='host_name' ./manage.py runserver > > but I get the following error: > > Access denied for user 'cdraccess'@'host_ip_here' (using password: NO)") > >
This error message comes up when attempting to log in to MySQL only using a user name, and not providing a password. It is a valid way to log in, but if the resourced/DB you are using has a password tied to it, then you'll get a message like this. > I tried to access the database from terminal, like: > > $ mysql --host=[host_name] --user=cdraccess -p portal2 > > You can replicate the error by removing the -p option from this command. > and worked fine. > > What is going wrong in here? And what does this "(using password: NO)" > mean? > My guess is that CDR_DB_PASSWORD is either not being properly populated, or not being passed correctly to your settings file. I'm guessing that PASSWORD is being populated with an empty string ("") from your .get() call, so Django is just not using it when it attempts to log into the database. Try temporarily adding the password as the default value for .get('CDR_DB_PASSWORD', '<mypass>') and ensure things are working from there, or just set the variable directly for testing purposes. If that works, revert it back to your current setup and add a print('DB Password: ', DATABASES['cdraccess']['PASSWORD']) (or without parentheses for Python 2), and that should print out a line in the dev server console, hopefully something like 'DB Password: <password>'. That will verify your PASSWORD field is being populated correctly. My guess is that it will print 'DB Password:' with no password from the way you describe it (since you are printing an empty string). -James -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUUWTA81BYc0k2KsLKU0LfOcb6LCQRzG4eT4ueyfyxdKg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.