django.db.utils.OperationalError: (1045, Access denied for user user@localhost

2024/10/14 21:25:02

I can't get my Django project to load my database correctly. It throws this error.

I'm running MariaDB with Django, and I uninstalled all MySQL

I added the user by running:

create database foo_db;
create user foo_user identified by 'foo_password';
grant all on foo_db.* to 'foo_user'@'%';
flush privileges;

as suggested by this post.

The console is throwing me this error back when I try to run ./manage.py runserver

django.db.utils.OperationalError: (1045, "Access denied for user '<user>'@'localhost' (using password: YES)")

I have run the 'create user' command and created the user to match my setup script, which has the default set as:

        'ENGINE': 'django.contrib.gis.db.backends.mysql','NAME': 'company_production','USER': 'companydev','PASSWORD': 'companydevpass','HOST': 'localhost','PORT': '','ATOMIC_REQUESTS': True

I have tried everything I've been able to find on here related to the error its thrown, but nothing has been working.

I'm running Mac OSX 10.11.1 El Capitan and MariaDB version 10.1.8 if that's relevant at all.

Answer

This is what I use to re-create MySQL databases for Django projects:

tmp="/tmp/mysql-tools.sh.tmp"setup-db ( ) {cat <<EOF > $tmp
DROP DATABASE $DB;
CREATE DATABASE $DB;
GRANT USAGE on *.* to '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}';
GRANT ALL PRIVILEGES ON ${DB}.* to '${DB_USER}'@'localhost';
EOFcat $tmpmysql -f -u ${MYSQL_ROOTUSR} -p${MYSQL_ROOTPWD} < $tmprm $tmp
}

Warning: this drops and re-creates!

Where:

  • DB: the database name
  • DB_USER: the django database user
  • DB_PASS: the password for the mysql connection for the Django database user
  • MYSQL_ROOTUSR: the mysql root user (must have permissions to create databases)
  • MYSQL_ROOTPWD: the mysql root password

Export those in your environment

https://en.xdnf.cn/q/117908.html

Related Q&A

Paho Python Client with HiveMQ

i am developing a module in python that will allow me to connect my raspberry pi to a version of hivemq hosted on my pc.it connects normally but when i add hivemqs file auth plugin it doesnt seem to wo…

Comparison of value items in a dictionary and counting matches

Im using Python 2.7. Im trying to compare the value items in a dictionary.I have two problems. First is the iteration of values in a dictionary with a length of 1. I always get an error, because python…

how to send cookies inside post request

trying to send Post request with the cookies on my pc from get request #! /usr/bin/python import re #regex import urllib import urllib2 #get request x = urllib2.urlopen("http://www.example.com) #…

Flask-Uploads gives AttributeError?

from flask import Flask from flask.ext.uploads import UploadSet, configure_uploads, IMAGESapp = Flask(__name__)app.config[UPLOADED_PHOTOS_DEST] = /home/kevin photos = UploadSet(photos, IMAGES)configure…

Python: Alternate way to covert from base64 string to opencv

Im trying to convert this string in base64 (http://pastebin.com/uz4ta0RL) to something usable by OpenCV. Currently I am using this code (img_temp is the string) to use the OpenCV functions by convertin…

Move 3D plot to avoid clipping by margins

Im trying to figure out how I can get the 3D matplotlib images below to plot higher on the canvas so it doesnt get clipped. Here is the code Im using to create the plot. I couldnt find a way to attach …

HTML Link parsing using BeautifulSoup

here is my Python code which Im using to extract the Specific HTML from the Page links Im sending as parameter. Im using BeautifulSoup. This code works fine for sometimes and sometimes it is getting st…

XML format change using XSL file in a Python code

Have written a Python code to transform a XML file to a particular format using XSL stylesheet. Python code below:#!/usr/bin/env python # -*- coding:utf-8 -*- from lxml import etree def transform(xmlP…

How to extract a specific value from a dictionary in python

I want to extract distance from google distance matrix API in Python. The objet it returned is a python dictionary.{destination_addresses: [Mumbai, Maharashtra, India ],origin_addresses: [Powai, Mumbai…

label on top of image in python

I am trying to display text on top of an image. Right now the text is below the image or if I put a row=0 in the grid disappears. I am assuming it is behind the image. I cant seem to get it to work. My…