Mysql error: PHP Warning: mysql_connect (): mysqlnd cannot connect

Source: Internet
Author: User
Tags mysql database

Recently I updated the PHP version. When using the mysql_connect () function, an error is returned:

 

PHP Warning: mysql_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 in/root/test. php on line 3

 

Cause:

 

To be compatible with versions earlier than MySQL 5.0, the user password (password field in the user table of mysql database) stores the 16-bit hash value of the password, the mysql driver after PHP5.3 uses the 41-bit password hash value for user verification. Therefore, you need to have mysql save the 41-bit hash value of the user password, but in the configuration file, if old_passwords = 1, the password () function can return only 16-bit hash values.

 

The solution is as follows:

SET old_passwords = 0; UPDATE mysql. user set password = PASSWORD ('phpddt. com ') WHERE User = 'root' LIMIT 1; select length (PASSWORD) FROM mysql. user WHERE User = 'root'; flush privileges;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.