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?
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;
Related
I am trying to connect deploy a django backend with postgres db on digitalocean droplet. But it's giving me this error after after gunicorn and nginx setup:
connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "rootuser" does not exist`
"rootuser" is my root username not the db username, my db username is dbadmin
I tried to create db user with name serveroot, it worked but started throwing other errors:
relation "django_site" does not exist LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...
Have a look at the docs about the settings file: https://docs.djangoproject.com/en/4.1/topics/settings/
Look for a section like this one:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': YOUR_DB_NAME,
'USER': USERNAME,
'PASSWORD': PASSWORD_FOR_DB,
'HOST': 'localhost' // in Development.
}
}
and then change the NAME, USER, PASSWORD and HOST values to the ones you need.
I am hosting a postgresql database on AWS using the RDS service. I am trying to connect the django project to the aws database using the settings.py file in the django project. I keep getting the following error:
connection to server at "database-1.xxxxxx.us-east-1.rds.amazonaws.com" (xx.xxx.xx.xxx), port 5432 failed: FATAL: password authentication failed for user "local_user"
This error is unexpected because it should not be trying to authenticate the local_user as this is the user for my local postgres server, it should be trying to authenticate the user for the hosted database, which is completely different.
This is what my settings file looks like:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('DATABASE_NAME'),
'USER': os.environ.get('DATABASE_USER'),
'PASSWORD': os.environ.get('DATABASE_PASSWORD'),
'HOST': "database-1.xxxxxx.us-east-1.rds.amazonaws.com",
'PORT': 5432
}
}
I can't figure out what the issue seems to be. Any help will be appreciated!
I named the environment variable wrong so USER was none!
I am trying to create tables for my models in this full stack project (Django/React). After I run the python manage.py migrate command I'm expecting to see:
Migrations for X:
X\migrations\0001_initial_py
- Create model Departments
- Create model Employees
Instead I get the following error: (9000, "Client with IP address 'X' is not allowed to connect to this MySQL server."
I have tried the command pip install pymysql
then edited the settings.py file adding
import pymysql
pymysql.install_as_MySQLdb()
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mytestdb',
'USER': 'testadmin#mytestmysql',
'PASSWORD': 'XXXXXXXXXX#',
'HOST': 'mytestmysql.mysql.database.XXXXXXXXXXXXX.com',
'PORT': '3306'
MySQL permissions are such that you have to specify 'user'#'host' when defining privileges. My guess is that you didn't set the MySQL database user up correctly.
Read here to understand what I'm referring to.
Here is Django setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'rulings',
'USER': 'postgres',
'PASSWORD': '******',
'HOST': '',
'PORT': '',
}
}
In AWS, when I run a server, an error message occurs.
File "/home/app_admin/venv_ruling/lib64/python3.7/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError:
FATAL: Peer authentication failed for user "postgres"
How can I run the server with the user name of postgres??
When I use another user name it will run without a problem, but I want to use "postgres" as a user.
I don't think "peer" authentication can even be configured on RDS, so you must be running your own PostgreSQL server on EC2? Since you apparently want to use password authentication, change your pg_hba to specify "md5", rather than "peer".
Also, it is a bad practise to run an app as "postgres". That user is supposed to be reserved for maintenance operations.
I'm trying to learn web development with Django and I was following this guide to do so.
Everything works fine until I run the following:
python manage.py makemigrations
I get this error message:
password authentication failed for user "myprojectuser"
I have checked and rechecked many times and the password is correct in the settings.py file.
Below is the content of the file (settings.py):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'myproject',
'USER': 'myprojectuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
I am using postgreSQL 9.5, python 2.7, and Django 1.10.
From your guide:
"
By default, Postgres uses an authentication scheme called "peer authentication" for local connections. Basically, this means that if the user's operating system username matches a valid Postgres username, that user can login with no further authentication.
"
so I am guessing that if you will create a user for your DB with the same name as your OS local username it might work :)
In case the "DATABASES" setting you showed are not the one you actually use - check if the "NAME" and the "USER" are in lowercase