Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL PHP incompatibility

Tags:

I'm running WAMP locally, but connecting to a remote MySQL database. The local version of PHP is the latest 5.3.0.

One of the remote databases, being version 5.0.45 works fine. However, the other remote database I'm trying to connect to, which is version 5.0.22 throws the following error before dying:

Warning: mysql_connect() [function.mysql-connect]: OK packet 6 bytes shorter than expected. PID=5880 in ...

Warning: mysql_connect() [function.mysql-connect]: mysqlnd cannot connect to MySQL 4.1+ using old authentication in ...

WTF?

UPDATE:

Reverting to PHP 5.2.* i.e. anything lower than 5.3.0 resolves the problem completely. As long as I am not running 5.3.0 I can connect to both databases. I'm not sure what the explanation is for this weirdness.

like image 778
Evernoob Avatar asked Aug 27 '09 11:08

Evernoob


People also ask

Which PHP version are compatible with MySQL?

PHP 7.4 now supports MySQL with caching_sha2_password, although it is a bit unclear around older versions, there seems to be conflicting reports.

Is PHP MySQL compatible?

With PHP, you can connect to and manipulate databases. MySQL is the most popular database system used with PHP.

Can not connect to MySQL in PHP?

PHP may not be able to connect to the MySQL server if the server name is not recognized. Make sure that the server name is set to localhost. In case of other errors, make sure to consult the error_log file to help when trying to solve any issues. The file is located in the same folder where the script is running.

Does PHP support MySQL 8?

The support of MySQL 8.0's new default authentication method in PHP took some time and was added in PHP 7.2. 8 but removed in PHP 7.2. 11. Now it's fully supported in PHP 7.4 !


1 Answers

The MySQL account you're using probably has an old 16 character long password (hash).
You can test that with a MySQL client (like HeidiSQL, the MySQL console client or any other client) and an account that has access to the mysql.user table. If the Password field contains 16 chars it's an old password and mysqlnd cannot use it to connect to the MySQL server.
You can set a new password for that user with

SET PASSWORD FOR 'username'@'hostmask' = PASSWORD('thepassword') 

see dev_mysql_set_password

edit:
You should also check if the server is set to use/create old passwords by default.

edit2:
Please run the query

SELECT   Length(`Password`),   Substring(`Password`, 1, 1) FROM   `mysql`.`user` WHERE   `user`='username' 

on the 5.0.22 server (the one that's "failing"). Replace username by the account you're using in mysql_connect().
What does that return?

like image 178
VolkerK Avatar answered Nov 22 '22 06:11

VolkerK