使用密码拒绝用户'root'@'localhost'访问:否

时间:2022-06-01 14:09:28

There are similar questions out there to this one, but I am not finding anything that is solving my issue.

对于这个问题有类似的问题,但我找不到任何解决我问题的方法。

I am working on a django project and made a database change and want to migrate the database change to production. So I run

我正在研究django项目并进行了数据库更改,并希望将数据库更改迁移到生产环境。所以我跑了

python manage.py migrate

But I receive this error

但是我收到了这个错误

OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

From what I understand I must not have permission to run the migration, but I did try

根据我的理解,我必须没有权限来运行迁移,但我确实尝试过

grant all privileges on *.* to root@localhost identified by 'password' with grant option;

and different combinations thereof, but to no avail.

和它们的不同组合,但无济于事。

In my local_settings.py I have

在我的local_settings.py我有

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',
        'NAME': 'stratinvnet',
    },
}

I've tried to change 127.0.0.1 to localhost and that seems to make no difference. I have also tried to remove the password from the DATABASES object.

我试图将127.0.0.1更改为localhost,这似乎没有任何区别。我还试图从DATABASES对象中删除密码。

For what it's worth, here is my GRANTS table in mysql.

对于它的价值,这是我在mysql中的GRANTS表。

 GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*5FE8B16533FAE91D61522C9A6811F3F709147255' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION

and here is the user table.

这是用户表。

 user       | host      | password                                  |
+------------+-----------+-------------------------------------------+
| root       | localhost | *5FE8B16533FAE91D61522C9A6811F3F709147255 |
| root       | 127.0.0.1 |                                           |
| root       | ::1       |                                           |
|            | localhost |                                           |
| root       | %         | *944B67F866A66B9DDD96024A97EBFDC886FC41F6 |
| phpmyadmin | localhost | *5FE8B16533FAE91D61522C9A6811F3F709147255 |

1 个解决方案

#1


0  

seems like you use socks file for mysql, try replace:

好像你使用socks文件for mysql,尝试替换:

'HOST': '127.0.0.1',

with this:

有了这个:

'HOST': '/var/lib/mysql/mysql.sock',  # 'HOST': 'localhost',

#1


0  

seems like you use socks file for mysql, try replace:

好像你使用socks文件for mysql,尝试替换:

'HOST': '127.0.0.1',

with this:

有了这个:

'HOST': '/var/lib/mysql/mysql.sock',  # 'HOST': 'localhost',