Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pythonanywhere: access denied for user 'USERNAME'@'%' to database

I am using www.pythonanywhere.com for deployment of my Django project. The pythonanywhere's database settings are as follows:

Connecting: 
    Database host address: mysql.server
    Username: Username (just as an example)

Your databases:
    Start a console on: Username$DBName  (just as an example)
    ...

While setting up the database using "manage.py migrate" command, The error message showed up:

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

DATABASES settings in file settings.py are as follows.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'DBName',
        'USER': 'Username',
        'PASSWORD': 'password',
        'HOST': 'mysql.server',
        'PORT': '3306',
    }
}

I am able to run mysql in the Console using the command:

$ mysql -u Username -h mysql.server -p

When I enter the following command:

mysql> use mysql;

I got the error message:

ERROR 1044 (42000): Access denied for user 'Username'@'%' to database 'mysql'

"show databases;" command shows there is no database named "mysql".

When I enter the following command:

mysql> GRANT ALL PRIVILEGES ON DBName.* TO 'Username'@'Username$DBName' IDENTIFIED BY 'password' WITH GRANT OPTION;

I also got the error message:

ERROR 1044 (42000): Access denied for user 'Username'@'%' to database 'DBName'

So, how do I setup the database?

like image 498
Randy Tang Avatar asked Oct 26 '14 08:10

Randy Tang


People also ask

How do I delete a database in PythonAnywhere?

To do delete a database you need the command 'DROP DATABASE'.

Is PythonAnywhere private?

Yes, files on your PythonAnywhere account are private unless you actively make them public. However, there are a couple of ways you could accidentally do that -- our help page on security has some details.

Does PythonAnywhere have database?

Databases availableThere are three databases built in to PythonAnywhere: MySQL, which is available for every user. SQLite, which is also available for everyone, but runs a bit slowly on our system -- we recommend you only use it for testing or for scripts that don't do a lot of processing.


1 Answers

Found this in the pythonanywhere documentation, the database settings to use MySQL should be of the form:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '<your_username>$<your_database_name>',
        'USER': '<your_username>',
        'PASSWORD': '<your_mysql_password>',
        'HOST': 'mysql.server',
    }
}

If your username is say user and database is db, then your database name should be user$db, not db.

Similarly, to access the database in the console you type

mysql>use user$db;

and not

mysql>use db;

like image 135
Abhinav Avatar answered Nov 24 '22 06:11

Abhinav