【问题标题】:django.db.utils.OperationalError: (1045, u"Access denied for user 'my_user'@'localhost' (using password: NO)")django.db.utils.OperationalError: (1045, u"Access denied for user 'my_user'@'localhost' (using password: NO)")
【发布时间】:2018-12-29 08:22:15
【问题描述】:

我正在尝试从 DJango 连接到 MySQL。 我的 settings.py 文件:

DATABASES = {
          'default':{
             'ENGINE': 'django.db.backends.mysql',
             'Name': 'my_db',
             'User': 'my_user',
             'Password': 'my_pass',
             'Host': 'localhost',
             'Port': '3306'
          }
}

}

我收到以下错误。

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

我已尝试以下步骤来解决问题。

我已经创建了用户:

    create user 'my_user'@'localhost' identified by 'my_pass';

并按如下方式授予访问权限:

    grant all on *.* to 'my_user'@'localhost';
    flush privileges;

但是,即使我的问题还没有解决。 有人可以帮我吗?

谢谢。

【问题讨论】:

  • 我在尝试解决方案后发布了这个问题。我已授予用户访问权限。但是,即使我遇到了同样的错误。
  • @ShankarMuthusamy 你是否能够使用 mysql 客户端使用上述凭据访问 mysql shell?
  • @RiteshAgrawal,是的,我可以使用凭据访问 mysql shell。

标签: mysql django django-mysql


【解决方案1】:

所有数据库配置变量都需要大写,但您已在标题大小写中提供。

DATABASES = {
      'default':{
         'ENGINE': 'django.db.backends.mysql',
         'NAME': 'my_db',
         'USER': 'my_user',
         'PASSWORD': 'my_pass',
         'HOST': 'localhost',
         'PORT': '3306'
      }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 2018-08-17
    • 1970-01-01
    • 2016-09-28
    • 2012-04-28
    • 1970-01-01
    相关资源
    最近更新 更多