Django AWS MySQL - django

I tried to deploy my application on AWS, but I'm having problems!
First, when trying to put MySQL data in settings.py, a problem appears:
"Unknown MySQL server host 'myapp.us-east-1.rds.amazonaws.com'
I tried with other databases (Postgresql and Oracle) and they worked, but mysql did not.
Does anyone know how to solve? I would be grateful. Gratitude.

Please confirm, your setting file should be like below:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'xxx',
'USER': 'xxx',
'PASSWORD': 'xxx',
'HOST': 'xxx.xxx.us-east-1.rds.amazonaws.com',
'PORT': '3306',
}
}

Related

ElephantSQL and Django not working together, atuhentication failed

I have bumped into the following problem and still don't know how to fix it. For the record I am using mac.
I would like to connect my djnago app to an elephantsql database, so I have changed the database info.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'abc',
'USER':'abc',
'PASSWORD':'password',
'HOSTS':'tai.db.elephantsql.com',
'PORT': 5432
}
}
I see my database working fine in pgAdmin 4, so there is no issue with that, but when I run
python manage.py migrate
got the following error:
django.db.utils.OperationalError: FATAL: password authentication failed for user "abc"
Do you have any tips how to go forward?
You specify the host of the database with the HOST key, not the HOSTS for the DATAbASES setting [Django-doc]:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'abc',
'USER': 'abc',
'PASSWORD': 'password',
# ↓ HOST instead of HOSTS
'HOST': 'tai.db.elephantsql.com',
'PORT': 5432
}
}

Solve a connection refuse error in PostgreSQL database

How do I solve this operational error? I have deployed my Django website and I have some issues with the database connection
my settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'avc',
'USER': 'postgres',
'PASSWORD': '****',
'HOST': 'localhost',
'PORT':'5432'
}
}
I am using Postgres 10
this is the error database refused the client request,
error
I assume Django needs psycopg2 to connect
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'avc',
'USER': 'postgres',
'PASSWORD': '****',
'HOST': 'localhost',
'PORT':'5432'
}
}
As well check if pg_hba.conf is accepting connections
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
please refer step by the step installation guide by edb
https://www.enterprisedb.com/postgres-tutorials/how-use-postgresql-django

Specify the --ssl option for django database connection

When I connect to my database with mysql I specify the option --ssl, or else I get the error
SSL connection is required. Please specify SSL options and retry.
I know that with MySQL you can connect with a ssl certificate where you have a copy of the certificate locally. With this approach I know how to move forward with Django, as you can specify the option as described here https://stackoverflow.com/a/12285601/2889451
However, in my case I simply pass the option --ssl, and I don't have a local copy of the certificate.
How can I enable this option in Django?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': DB_NAME,
'USER': DB_USER,
'PASSWORD': DB_PASSWORD,
'HOST': DB_HOST,
'PORT': '',
}
}
Apparently you can solve it by passing the options as shown below:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': DB_NAME,
'USER': DB_USER,
'PASSWORD': DB_PASSWORD,
'HOST': DB_HOST,
'PORT': '',
'OPTIONS': {'ssl': True},
}
}

Django always connects to localhost mongodb

I have followed the guide of db connection config:
https://nesdis.github.io/djongo/database-configuration/
However, it always connects to localhost one, not my setting's one.
Does anyone have any idea on this issue?
my packages versions:
Django 2.0
django-cors-headers 2.4.0
django-rest-auth 0.9.3
djangorestframework 3.9.0
djongo 1.1
mongoengine 0.16.3
pip 10.0.1
pymongo 3.7.2
urllib3 1.24.1
my settings
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'test_db',
'HOST': 'somewhere.com',
'PORT': 27017
}
}
Is seems that somewhere along the way, djongo changed the structure of the database settings. After wasting days trying to find the solution, I came across a page that had the updated structure, Try setting your DATABASE structure to this:
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'yourmongodb',
'CLIENT': {
'host': 'some-host.or.ip',
'port': 27017,
'username': 'youruser',
'password': 'yourdbpass',
'authSource': 'yourcollection',
}
},
}
Have you edited your setting in the settings.py file
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'XXXX',
'USER': 'XXX',
'PASSWORD': 'XXXX',
'HOST': 'XXX.XXX.XXX.XXX',
'PORT': '3306',
'OPTION': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
}
}
}
First: Create a SSH Tunnel to remote mysql server on localhost
ssh -N -L 3306:127.0.0.1:3306 root#192.168.0.122
192.168.0.122 >> is a remote LAN server of mine.
Second : use 127.0.0.1 as a HOST on Django connection string.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'XXXX',
'USER': 'XXX',
'PASSWORD': 'XXXX',
'HOST': '127.0.0.1',
'PORT': '3306',
'OPTION': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
}
}
OR change HOST to 127.0.0.1 in .env if using environment file.
This worked for me.

How to connect with Django and external mysqlDB

I have 2VM. One is the "Apache+Django" server and one Mysql server.
I want to know that How connect the Django and externel mysql ?
Change below setting in your settings.py file
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydb', # remote db name
'USER': 'root', # remote db user
'PASSWORD': 'mypass', #remote db pass
'HOST': 'remote.ip.address.something',#remote ip or url
'PORT': '3306', # remote post
}
}