正在加载中...

已解决:mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication密码兼容问题

已解决:mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication密码兼容问题

mysqlnd是个好工具,不仅可以提高与mysql数据库通信的效率,而且也可以方便地进行数据库超时管理。如,连接超时,查询超时。
但是,使用mysqlnd的时候,有个地方需要注意。就是服务端的密码格式不能使用旧的16位的存储格式,而要使用新的41位的存储格式。
如果,服务端的密码格式是16位,那么就会报错。

mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD(‘your_existing_password’). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file. SQL 错误代码: “7335941”.

是采用兼容格式的密码,而 php5.3的php_mysql; php_pdo_mysql 采用的是增强的密码,所以导致两者不匹配,最方便的方式还是更新db的设置,取消 old_passwords
然后在 mysql.mysql.user,更新所有用户的密码, 如:

SET old_passwords =0;
UPDATE mysql.user SET Password =PASSWORD('testpass') WHERE User='testuser' limit 1;
SELECT LENGTH(Password) FROM mysql.user WHERE User='testuser';
FLUSH PRIVILEGES;


如何查看自己的密码是否符合要求

mysql> select user,length(password) from mysql.user; 
+--------------+------------------+
| user         | length(password) |
+--------------+------------------+
| demo         |               16 | 
| demo         |               16 | 
+--------------+------------------+

上面的密码是旧的16位格式。如果想改成新的41位格式,通过以下命令就可以。


mysql>UPDATE mysql.user SET Password = PASSWORD('demo') WHERE user = 'demo';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0
mysql> select user,length(password) from mysql.user;
+--------------+------------------+
| user         | length(password) |
+--------------+------------------+
| demo         |               41 |
| demo         |               41 |
+--------------+------------------+
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

修改完密码后,还需要在配置文件中修改下old_passwords选项。把值设置为0。即,
old_passwords=0
然后重启mysql。


返回上一页