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?
To do delete a database you need the command 'DROP DATABASE'.
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.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With