Forums

Access denied for database

Hi,

Im having a problem in database connection. I successfully run the python manage.py syncdb, but when i browse it say's Access denied for user.

Any thoughts what I having the problem?

Is it MySql? As for me, mySql connection works; There should be right parameters: DB&user name, host (mysql.server), et c

Hi cmora -- what tool are you using to browse the database?

@giles im just using the console to browse the database. If my user parameters is wrong it shouldn't have successfully run the python manage.py syncdb. When i run the syncdb it did create the all my tables. That's why I'm confuse, the syncdb is also using the settings.py so how come it is not working when browse the url.

Ok i try this on my console.

python manage.py shell

then i import my models and query no error i got.

sample:

from mysite.models import Table1

Table1.objects.all()

[]

only means that user account is ok.

but when i browse mysite i got this error

OperationalError: (1045, "Access denied for user 'cmora'@'ip-10-90-207-138.ec2.internal' (using password: YES)")

my settings.py is

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'cmora$default', 'USER': 'cmora', 'PASSWORD': 'notmyrealpassword', 'HOST': 'mysql.server', 'PORT': '3306', } }

and my wsgi is

activate_this = '/home/cmora/Envs/django/bin/activate_this.py'

execfile(activate_this, dict(file=activate_this))

import os

import sys

path = '/home/cmora/mysite'

if path not in sys.path: sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

Am i doing something wrong in the wsgi?

Thanks in advance

Hi there -- my guess is that you didn't restart your web ap after entering the DB settings in settings.py -- I visited your web page, saw the error, hit the "Reload web app" button (you can do that from the "Web" tab), and it now seems to work.

In general, you need to reload the web app after making any code changes; we're looking into ways of making that more obvious.

Oh (facepalm) thanks a lot. yeah that it

thanks so much

No problem!

facepalm...wow, I haven't heard that in years. I had a friend who used to say it all the time. Thanks for giving me a smile!!

I'm having the exact same issue, and reloading doesn't help. I'm trying to execute a raw query, in Django, and get that error, as well as when I try to access mysql in the shell.

@ztorstri: are you sure you have the correct parameters in your settings.py? Check

  • the database name (should contain your username and a $),
  • the password (this is set on the databases tab, you can experiment with resetting it),
  • and the host (mysql.server)...

I'm sure. I can do syncdb, and I can run Django queries, I just can't do raw queries with Django or command line raw queries.

Here's the actual error: "SELECT command denied to user 'ztorstri'@'domU-12-31-38-04-BD-28.compute-1.internal' for table 'Order

and the stacktrace can be seen here: http://ztorstri.pythonanywhere.com/queries/

From the statcktrace, it looks like you're trying to access a table called Person (presumably that's what your model is called). The Django ORM creates tables with the application name as a prefix. So from your stacktrace (and this is just a guess, you'd have to check your actual database for the real value), it's much more likely that the table you want to access is called something like humans_person.

I'm also having trouble doing things at the command line, so its difficult to troubleshoot anything.

mysql> SHOW TABLES FROM ztorsri$default; ERROR 1044 (42000): Access denied for user 'ztorstri'@'%' to database 'ztorsri$default'

If I change the table name (say, to just person), I get the following:

146, "Table 'ztorstri$default.person' doesn't exist"

So I must have had it named right before. There's some kind of weird permissions thing happening on the server.

Two things:

1) In your last-but-one post, you spelled your username wrong, I think. "ztorsri" instead of "ztorstri"

2) If you go to the "Databases" and click on the name of your database, it'll give you a MySQL console, ready and logged into that database

Other problems may be to do with quoting -- bash and mysql can be a bit funny about the "$" character, so you may have to experiment with various types of quoting.... But, experimenting just now, the USE command should work without quotes, eg:

USE ztorstri$default;

Which will switch to that database. You should then be able to do

SHOW TABLES;

I think I've finally figured it out. It would seem the table was named wrong, though I'm sure I tried this version of naming before. The trick of clicking on the db name was very useful; thank you. It allowed me to see how the tables were named in the database, and thus eliminate that variable from the problem.

Also, nice catch on the misspelling. Maybe I misspelled at another point in time too, and was doing the right thing with the wrong spelling.

It seems to be random whether it says "SELECT command denied to user.." or "Table does not exist...". Any insight there?

Hmmm. Could it be that you get a "SELECT command denied" if mysql interprets it as you wanting a table from a different database?

I had the same problem and the reason is that you have to put the database name as Username$YourDatabaseName in the settings file

Iam Unable to connect to MYSQL it shows the error like _mysql_exceptions.OperationalError: (1045, "Access denied for user 'hariprakashs'@'10.0.0.7' (using password: NO)")

requesting for fast reply

The error message says that you're not specifying a password; if you fix that, it should work fine. Use the password you entered on the "Databases" tab when you originally configured MySQL.

I get my feedback when I run the command " python manage.py migrate"

django.db.utils.OperationalError: (1044, "Access denied for user 'bakz'@'%' to database 'bakz'")

You;'re not using the correct database name. All MySQL databases on PythonAnywhere have a $ in them. Your database names are shown on the Databases tab.

I'm getting an error on accessing the database that I haven't gotten before. (I haven't updated anything on the web app in a while and everything worked fine previously so not sure what's changed.)

  1. When I run python manage.py makemigrations in the bash console, I get this error: django.db.utils.OperationalError: (1044, "Access denied for user 'Kruizetech'@'%' to database 'Kruizetech'").

  2. I have restarted my web app, checked all of my spelling/capitalization and have even tested making changes to the database from the Django admin (Admin works so it appears that my DATABASE settings are correct), but I continue to get this error in the console.

  3. I have tried specifying the exact setting file as well (python manage.py makemigrations --settings=config.settings.prod-pa) but get the same result.

Any thoughts on what to try next? The site is running fine, but I am planning to make changes that I won't be able to migrate until this error is resolved. Thanks!

Your database should be something like Kruizetech$default instead of Kruizetech

@conrad, it is set up as Kruizetech$default. That's the problem. All the settings are correct and the Django application is working as expected. I am able to update the database via the Admin as expected.

The issue is that I cannot access it from the command line using python manage.py makemigrations or other data related commands. Also please note that everything worked fine previously. I've never had this issue before using the same settings.

I guess I'm on my own. (Disappointing answer when you guys are usually awesome with support.)

Do you run your commands while in the correct virtual environment and with correct settings? Seams to be true as you mention in point 3 but make sure.

I figured it out! I reviewed the documentation under using MySQL and saw the note about verifying the database name was in parenthesis.

Answer:

  1. In the bash console, I deactivated my virtual environment.
  2. Modified my .env file and put the database name in parenthesis: export DATABASE_NAME='Kruizetech$default'
  3. Reactivated my virtual environment: workon venv

Now it works and I can run the database-related commands. (I'm not sure why it wasn't a problem previously, but I'm happy I got it working.) Also strange that Django worked just fine with out the parenthesis, but must be a feature of the package I'm using to load the .env file. :: shrug ::

Note: You must deactivate then reactivate in order to load your environmental variables. I didn't do this yesterday when troubleshooting. I believe I would have found the answer sooner if I had.

Glad to see that you found it.

'db': 'a4amaan$kitabcha', 'host': 'a4amaan.mysql.pythonanywhere-services.com', 'init_command': 'ALTER DATABASE a4amaan$kitabcha CHARACTER SET utf8mb4 ' 'COLLATE utf8mb4_general_ci;SET ' 'default_storage_engine=INNODB; SET ' "sql_mode='STRICT_TRANS_TABLES'", 'passwd': 'Pa$$w0rd',

Please check whats wrong with django database. Getting same error: https://a4amaan.pythonanywhere.com/admin/login/?next=/admin/

Your site seems to be working and your database settings look correct. So that means, it must be that you're using the wrong password. Make sure you're using the password that you set when you originally set up your MySQL database.

Hello, I'm getting access denied error with mysql: mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'madhuchaliyan'@'10.0.0.175' (using password: YES). Following parameters value I have passed as per the documentations. Please advise. I am trying to connect from pythonanywhere only. host, user, password" database

Where do you run that? Are you sure that the credentials used are database credentials, not the PythonAnywhere ones?

I had a similar issue with error 1044 and after changing the .env file database name like Kruizetech suggested, everything worked out fine.

Why is this the case? I thought that all environment variables should be without the quote marks?

it's because of $ in the database name.