django.db.utils.OperationalError:(1045,用户'< user>'@@ localhost'的访问被拒绝 [英] django.db.utils.OperationalError: (1045, Access denied for user '<user>'@'localhost'

查看:138
本文介绍了django.db.utils.OperationalError:(1045,用户'< user>'@@ localhost'的访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得Django项目来正确加载数据库.它引发此错误.

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

我在Django上运行MariaDB,并且卸载了所有MySQL

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;

此帖子建议.

当我尝试运行./manage.py runserver

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

我已经运行了'create user'命令并创建了与我的设置脚本匹配的用户,该设置脚本的默认设置为:

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.

我正在运行Mac OSX 10.11.1 El Capitan和MariaDB 10.1.8版,如果这真的很重要的话.

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

推荐答案

这是我用来为Django项目重新创建MySQL数据库的方法:

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';
EOF
    cat $tmp
    mysql -f -u ${MYSQL_ROOTUSR} -p${MYSQL_ROOTPWD} < $tmp
    rm $tmp
}

警告:它会掉落并重新创建!

Warning: this drops and re-creates!

位置:

  • DB:数据库名称
  • DB_USER:Django数据库用户
  • DB_PASS:Django数据库用户的mysql连接的密码
  • MYSQL_ROOTUSR:mysql根用户(必须具有创建数据库的权限)
  • MYSQL_ROOTPWD:mysql根密码

导出您环境中的内容

这篇关于django.db.utils.OperationalError:(1045,用户'&lt; user&gt;'@@ localhost'的访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆