PHP connection to MySQL fails with the "cannot connect to MySQL 4.1+ using the old insecure authentication" error

更新时间:
复制 MD 格式

After you deploy your PHP application to a Web Hosting instance, you may receive the "cannot connect to MySQL 4.1+ using the old insecure authentication" error when connecting to the database. This topic describes the possible causes of this error and how to resolve it.

Symptoms

The following error message is displayed:

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

Possible causes

This PHP client restriction applies because Web Hosting provides MySQL databases of version 5.1 or later. This error occurs if your application uses PHP 5.3 or later but attempts to authenticate with a password stored in the old format.

Solution

You must update the database password to use the 41-character encryption format. This format is required for applications that use PHP 5.3 or later.

This requirement is noted on the advanced environment settings > PHP version settings page in the Web Hosting console.

Follow these steps to set the encryption mode to the 41-character format.

  1. On the Web Hosting console > database information page, click reset password for your database.

  2. In the database password reset dialog box, click OK.

  3. Follow the prompts to enter a new password. This process automatically sets the encryption mode to the required 41-character format.

  4. Click OK. You must then update the password in your application's configuration file.