I’m working on building an ideal server setup that allows for both PHP 4 and PHP 5 on Apache with suPHP (I’ll blog about this later). While testing my PHP 4 build, I got the following error:
Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in /var/www/test-php.php on line 3 Couldn't authenticate with MySQL
The code I used to test this is quite simple:
if ( false === ( $db = mysql_connect( 'localhost', 'username', 'password' ) ) ) die( "Couldn't authenticate with MySQL" ); if ( false === mysql_select_db( 'database' ) ) die( "Couldn't connect to database" ); echo "Yay!"; ?>
After digging around for a bit, I found that mixing PHP 4 with a MySQL version greater than or equal to 4.1 causes this problem. MySQL 4.1 introduced a new password caching scheme that PHP 4 can’t work with.
The solution is to update the database user’s password using the OLD_PASSWORD function of MySQL. For example:
[chris@office ~]$ mysql -u root -p mysql Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 267 Server version: 5.1.41-3ubuntu12.1 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> update user set Password=OLD_PASSWORD('password') WHERE User='username'; Query OK, 0 rows affected (0.02 sec) Rows matched: 0 Changed: 0 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>
Note the underlined areas. That is where you’ll want to provide your own username and password.
Once you’ve followed these steps, both PHP 4 and PHP 5 will be able to communite with the database.
Thanks to digitalpeer for providing the answer to my issue.