mysql鉴权协议的问题

Client does not support authentication protocol requested by server

1 -- 错误原因分析

今天上线系统时遇到的一个问题:可执行程序使用MySQL4.0.22版本提供的静态库编译,运行时数据库服务器是5.0.33版本,当程序真正执行连接数据库时,曝出下面的错误消息。

Client does not support authentication protocol requested by server; consider upgrading MySQL client

查询MySQL的帮助文档,它给出这样的提示

MySQL 5.1 uses an authentication protocol based on a password hashing algorithm that is incompatible with that used by older (pre-4.1) clients. If you upgrade the server from 4.0, attempts to connect to it with an older client may fail with the message

翻译过来大致原因是MySQL自4.1以后使用了不同的鉴权协议,该协议与4.1之前的版本有着很大的不同。所以如果你的客户端是4.1之前的版本,那么在连接高版本的数据库时就会出现这样的错误。

2 -- 解决方法

1、Upgrade all client programs to use a 4.1.1 or newer client library
升级客户端程序使用4.1.1或者更高版本的客户端库。

2、When connecting to the server with a pre-4.1 client program, use an account that still has a pre-4.1-style password
连接数据库时,使用升级以前已经存在的账户,这些账户使用早于4.1版本的密码格式。

3、Reset the password to pre-4.1 style for each user that needs to use a pre-4.1 client program
使用早于4.1版本的密码格式重新设置账户密码,函数SET PASSWORDOLD_PASSWORD()用来完成修改。可以使用下面的任一方法来重置。
方法1:

mysql> SET PASSWORD FOR 'some_user'@'some_host' = OLD_PASSWORD('newpwd');

方法2:

mysql> UPDATE mysql.user SET Password = OLD_PASSWORD('newpwd')
-> WHERE Host = 'some_host' AND User = 'some_user';
mysql> FLUSH PRIVILEGES;
3 -- 参考资料

1、http://dev.mysql.com/doc/refman/5.1/en/old-client.html

原文地址:https://www.cnblogs.com/motadou/p/1698346.html