Django/MySQL-python - 使用旧(4.1.1 之前)身份验证协议的连接被拒绝(客户端选项“secure_auth”已启用)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22023387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:05:36  来源:igfitidea点击:

Django/MySQL-python - Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)

pythonmysqldjango

提问by sleepycal

So many people have experienced this problem on SO, yet almost all the answers are useless.

这么多人在SO上遇到过这个问题,但几乎所有的答案都是无用的。

Traceback (most recent call last):
  File "/venv/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
    self.validate(display_num_errors=True)
  File "/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate
    num_errors = get_validation_errors(s, app)
  File "/venv/local/lib/python2.7/site-packages/django/core/management/validation.py", line 103, in get_validation_errors
    connection.validation.validate_field(e, opts, f)
  File "/venv/local/lib/python2.7/site-packages/django/db/
backends/mysql/validation.py", line 14, in validate_field
    db_version = self.connection.get_server_version()
  File "/venv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 415, in get_server_version
    self.cursor().close()
  File "/venv/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 306, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/venv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 387, in _cursor
    self.connection = Database.connect(**kwargs)
  File "/venv/local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/venv/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2049, "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)")

采纳答案by sleepycal

After much trial/error, the problem was narrowed down to passwords using an old encryption style.

经过多次尝试/错误,问题被缩小到使用旧加密风格的密码。

mysql> select User, Password from mysql.user;
| user1           | *113D91F3A36D29C287C457A20D602FA384B8569F |
| user2           | 5d78f2535e56dfe0 |

Tools such as Navicat do not automatically use newer style passwords, and you have to explicitly tell it to not use old style (in Navicat, it's called Advanced/Use OLD_PASSWORD tncryption) - this is where we got tripped up.

像 Navicat 这样的工具不会自动使用新式密码,你必须明确告诉它不要使用旧式密码(在 Navicat 中,它被称为高级/使用 OLD_PASSWORD tncryption)——这就是我们被绊倒的地方。

If you're using mysql shell, you can just use;

如果您使用的是 mysql shell,则可以使用;

mysql> update mysql.user set password=PASSWORD("NEWPASSWORD") where User='testuser';
Query OK, 1 row affected
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select User, Password from mysql.user WHERE user = 'testuser';
| testuser | *B845F78DCA29B8AE945AB9CFFAC24A9D17EB5063 |

If you want to find all users affected by this problem;

如果要查找所有受此问题影响的用户;

mysql> SELECT Host, User, Password FROM mysql.user WHERE LENGTH(Password) = 16;

Some versions of Django do not allow you to use secure-authinside the options, but for those that do you can use;

某些版本的 Django 不允许您secure-auth在选项内使用,但对于那些您可以使用的选项;

'OPTIONS': {
    'secure-auth': False
}

If it's unsupported, it will result in;

如果它不受支持,则会导致;

TypeError: 'secure-auth' is an invalid keyword argument for this function

This should hopefully serve as a quick answer for those having trouble in the future.

这应该有望成为那些将来遇到麻烦的人的快速答案。

回答by Md Azaharuddin Ali

For MySQL Workbench 6.08 in the Manage Server Connections, Connection tab, Advanced sub-tab you must check the box 'Use the old authentication protocol.'

对于 MySQL Workbench 6.08,在 Manage Server Connections、Connection 选项卡、Advanced 子选项卡中,您必须选中“使用旧身份验证协议”框。

enter image description here

在此处输入图片说明

回答by Mariano Ruiz

I had the same problem trying to connect with mysqlcommand line client, and I could avoid the error with --skip-secure-authoption.

我在尝试连接mysql命令行客户端时遇到了同样的问题,我可以通过--skip-secure-auth选项避免错误。

For example:

例如:

mysql DBNAME -h HOST_NAME_OR_IP -u DB_USER --password="PASSWORD" --skip-secure-auth

Same parameter for the other mysqlXcommands like mysqldump.

其他mysqlX命令的相同参数,如mysqldump.