Django:1045,"用户拒绝访问

时间:2017-06-09 15:13:52

标签: python mysql django

我已经阅读了很多堆栈溢出问题两天,但我无法弄清楚问题(我正在使用Mac)。

我做了:mysql -u root -p

所以它要求输入密码,并且root密码为空,不仅仅是输入让我进入mysql监视器并且我收到了消息:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is xxx
Server version: 5.7.18 Homebrew

然后:mysql> CREATE DATABASE concon CHARACTER SET utf8;

所以:mysql>CREATE USER 'concon'@'localhost' IDENTIFIED BY 'thepassword';

最后:mysql> GRANT ALL ON concon.* TO 'concon'@'localhost'

所以我退出mysql并运行sudo python manage.py runserver

问题是我收到了:django.db.utils.OperationalError: (1045, "Access denied for user 'concon'@'localhost' (using password: YES)")

我的dataBase是(在settings.py中):

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'concon',
        'USER': 'concon',
        'PASSWORD': 'thepassword',
        'HOST': 'localhost',
        'PORT': '',
    }
}

当我这样做时:SHOW GRANTS FOR 'concon'@'localhost'; 它显示:

+------------------------------------------------------------+
| Grants for concon@localhost                                |
+------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'concon'@'localhost'                 |
| GRANT ALL PRIVILEGES ON `concon`.* TO 'concon'@'localhost' |
+------------------------------------------------------------+

1 个答案:

答案 0 :(得分:0)

尝试此命令: "&MySQL的GT; FLUSH PRIVILEGES;" 在您向用户授予权限后