get (1045, "Access denied for user 'tony'#'localhost' when use environment variables [closed] - mysql

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 hours ago.
This post was edited and submitted for review 7 hours ago.
Improve this question
i'm on ubuntu 22.04
i connect my project to mysql whit environment variables:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': env('NAME'),
'USER': env("USER"),
'PASSWORD': env("PASSWORD"),
'HOST': env("HOST"),
'PORT': '',
}
}
and my .env file:
NAME=mysql
USER=root
PASSWORD=411481:011
HOST=localhost
return this error:
(1045, "Access denied for user 'tony'#'localhost'
but when didn't use environment variables that work
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mysql',
'USER': 'root',
'PASSWORD': '411481:011',
'HOST': 'localhost',
'PORT': '',
}
}
tip:i tried this on windows and worked

Related

Django & MeMSQL Error when running migrate.py: django.db.utils.OperationalError: (2012, 'Error in server handshake')

I have a Django application with a default MySQL database. I want to move my default Database to MeMSQL.
I set the credentials in settings.py to be:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': MEMSQL_DB,
'USER': MEMSQL_USER,
'PASSWORD': MEMSQL_PASSWORD,
'HOST': MEMSQL_HOST,
'PORT': '3306'
}
I try to run manage.py migrate to move all models to the new DB, and get this error:
django.db.utils.OperationalError: (2012, 'Error in server handshake')
If it helps - I tried to test the connection and credentials throughout a workbench (SQL-Pro), and it work successfully. only the manage.py migrate give me this error
When you connect from the latest version of Django to SingleStore DB, you might receive the following error message:
django.db.utils.OperationalError: (2012, 'Error in server handshake').
To connect to SingleStore DB, you will need to configure the auth_plugin in the OPTIONS field.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '{HOST}',
'NAME': '{DBNAME}',
'USER': '{USERNAME}',
'PASSWORD' : '{PASSWORD}',
'PORT': '3306',
'OPTIONS': {
'auth_plugin': 'mysql_native_password'
}
}
}

Django improperly loading while restarting it

I have a website that is in VPS hosting. I was supposed to restart it with the following code
source .venv/bin/activate
uwsgi --ini agros.ini
But I am receiving the following error
django.db.utils.OperationalError: (2006, 'MySQL server has gone away')
here is the database configuration in the settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'CONN_MAX_AGE': 3600,
'NAME': 'agros_new',
'USER': 'root',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': 3309,
}
}
this website uses Django version = 1.9 and the operating system is the Centos OS

django.db.utils.OperationalError: (1045, u"Access denied for user 'my_user'#'localhost' (using password: NO)")

I am trying to connect to MySQL from DJango.
My settings.py file:
DATABASES = {
'default':{
'ENGINE': 'django.db.backends.mysql',
'Name': 'my_db',
'User': 'my_user',
'Password': 'my_pass',
'Host': 'localhost',
'Port': '3306'
}
}
}
I am getting following error.
django.db.utils.OperationalError: (1045, u"Access denied for user 'my_user'#'localhost' (using password: NO)")
I have tried following steps to solve the problem.
I have created the user:
create user 'my_user'#'localhost' identified by 'my_pass';
And granted access as follows:
grant all on *.* to 'my_user'#'localhost';
flush privileges;
But, even though my problem not yet fixed.
Can someone help me?
Thanks.
All the database config variables need to be caps but you have provided in title case.
DATABASES = {
'default':{
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_db',
'USER': 'my_user',
'PASSWORD': 'my_pass',
'HOST': 'localhost',
'PORT': '3306'
}
}

can't connect mysql local server while deploy to aws

I am trying to deploy django rest app to AWS Elastic Beanstalk. I followed this tutorial and I configure DATABASES in setting.py like following
if 'RDS_DB_NAME' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME',
'USER': 'USER_NAME',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
}
}
and I add following code to .ebextensions directory,
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "myApp.settings"
"PYTHONPATH": "./src"
"ALLOWED_HOSTS": ".elasticbeanstalk.com"
"aws:elasticbeanstalk:container:python":
WSGIPath: [WSGI_PATH]
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python campusBackend/manage.py migrate --noinput"
leader_only: true
However, when I try to deploy, it gives me the error
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL
server through socket '/var/lib/mysql/mysql.sock' (2)").
container_command 01_migrate in .ebextensions/02_python.config failed.
I really stucked at this point and I have no idea how to solve this.
EDIT: I am using the following inbound/outbound rules for RDS

How do I tell Django to use MySql from a WAMP install?

I've had Django running with Sqlite for a while. I then installed WAMP, and I now want to get ready for a production run, and would like to switch to MySql. Is there a straightforward way of telling it about the MySql instance that is running with WAMP?
as Ignacio already has pointed out you have to modify your settings.py.
If you are using the latest version of Django (that would be 1.2.x) youe settings.py will contain this section:
DATABASES = {
'default': {
'ENGINE': '',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
Here you can define which database you are using.
In your case this section should look like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '',
'USER': 'your-mysql-username',
'PASSWORD': 'your-mysql-users-password',
'HOST': 'localhost',
'PORT': '3306',
}
}
If your are running a MySQL server it is identified by its IP address (localhost = 127.0.0.1) and its port (3306). You could run several MySQL server instances on the same computer. Each of this instances could be identified by the combination of its IP and port.
Hope that helps you.
Modify the database options in settings.py.
By default, these are the settings you should use with WAMP/MySQL I believe...
DATABASE_ENGINE = 'django.db.backends.mysql'
DATABASE_NAME = ''
DATABASE_USER = 'root'
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''
first install mysqldb module for python by typing following command:
easy_install mysql-python
on command prompt/python client and then modify your settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'Database Name',
'USER': 'Database Username',
'PASSWORD': 'Database Password',
'HOST': 'localhost',
'PORT': '3306',
}
}