最近做服务器部署,服务器mysql的版本是5.5.37,而客户端用的mysql库是5.6.15,结果就是死活连不上,开始以为是云服务器之间的路由不通。
不过经过核实之后,和链路无关。
然后在本地调试。输出连接失败信息如下:
mysql_connect(): Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)
mysql官网给的说明
| Command-Line Format | --secure-auth | ||
| Option-File Format | secure-auth | ||
| System Variable Name | secure_auth | ||
| Variable Scope | Global | ||
| Dynamic Variable | Yes | ||
| Permitted Values (<= 5.6.4) | |||
| Type | boolean | ||
| Default | OFF | ||
| Permitted Values (>= 5.6.5) | |||
| Type | boolean | ||
| Default | ON | ||
This option causes the server to block connections by clients that attempt to use accounts that have passwords stored in the old (pre-4.1) format. Use it to prevent all use of passwords employing the old format (and hence insecure communication over the network). Before MySQL 5.6.5, this option is disabled by default. As of MySQL 5.6.5, it is enabled by default; to disable it, use --skip-secure-auth.
1、服务器这边,在my.cnf中加上
secure-auth=1
重启 service mysqld start
2、客户端这边,mysql_options(mysql,MYSQL_SECURE_AUTH,(my_bool*)0);
建议采用方案1。
参考
http://blog.youkuaiyun.com/zuyi532/article/details/10148259

本文探讨了在使用不同版本的MySQL客户端连接服务器时遇到的连接失败问题,详细解释了secure-auth选项的作用及版本差异,并提供了在服务器端和客户端分别解决此问题的方法。
2136

被折叠的 条评论
为什么被折叠?



