Mysql password Error in PHP

拟墨画扇 提交于 2019-12-11 07:09:22

问题


When i try to connect a remote mysql server from my localhost i get this error:

Could not connect: 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

Any idea why it gives this error?


回答1:


It gives this error because your MySQL server uses the old way of storing password -- and not the new way, which is more secure.

The mysqlnd driver, which has been introduced with PHP 5.3, doesn't support the old authentication way.

So, you have to modify your MySQL configuration, to use the new, more secure way.
The error message you get is indicating you how to do that.




回答2:


this helped me

http://www.phpro.org/articles/Database-Connection-Failed-Mysqlnd-Cannot-Connect-To-MySQL.html

quick fix

as db user

SET SESSION old_passwords=0; 
SET PASSWORD=PASSWORD('my_password');

as admin

FLUSH PRIVILEGES;

real fix

open up your my.conf file and comment out the following line

old_passwords=1

Restart MySQL. this will ensure MySQL never uses the old passwords again.

as db user

SET PASSWORD=PASSWORD('my_password');

as admin

FLUSH PRIVILEGES;



回答3:


It seems to be an issue when running PHP <=5.2 code in PHP 5.3+: http://forums.mysql.com/read.php?52,403493,411125#msg-411125



来源:https://stackoverflow.com/questions/5687087/mysql-password-error-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!