11

I'm trying to run PHP 5.4.1 ( compiled from source ) but when i try to connect on mysql i get:

Warning: mysql_connect(): The server requested authentication method unknown to the client [mysql_old_password] in

When using PHP 5.3/5.2 it works normally. Any ideas of what cause this problem?

Fernando
  • 1,129
  • 6
  • 23
  • 32

5 Answers5

11

Try reading this: link

MySQL introduced longer password hashes in (i think) version 4.1, and your server probably still uses them (check for 16 byte password hashes in your mysql user table). Newer versions use longer password hashes. Your server supports both, but your client (php) seems to support only new ones in this version (and on).

If it's possible, use the solution from the link in the first line, and set your password again with the new hash, but beware, if you're using any other (old) clients which rely on old passwords, compatibility might break. Also try looking for old-password support for MySQL in PHP, but i'm not sure about it.

mulaz
  • 10,472
  • 1
  • 30
  • 37
  • This answer can be clearer and more detailed. PHP 5.2 appears to be the last PHP version with support for the 16 byte pre-MySQL-4-1 password hashes. The 'old' clients in this case are pre-MySQL-4.1 clients. – reinierpost May 17 '22 at 18:13
11
ALTER USER 'mysqlUsername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
Robin Qiu
  • 211
  • 2
  • 3
  • This answer solved this issue for me https://serverfault.com/questions/295285/mysql-cannot-connect-via-localhost-only-127-0-0-1/297310#297310 – Vishrant Aug 08 '19 at 03:54
  • I used cpanel to add a new DB user, and use this new user in my PHP code – Atara Jan 30 '22 at 08:28
4

I know this is an old topic, but I worked around the issue, without having to upgrade/downgrade anything. Basically I commented out the old_passwords=1 line in my my.cnf file, restarted mysql, added/modified the user which eventually got the 16 byte hash, then I went back and uncommented the old_passwords=1 line, and restarted mysql. So basically:

  • comment old_passwords=1
  • restart mysql
  • add/modify user
  • uncomment old_passwords=1
  • restart mysql

So there you have it: 1 user using new password type, while other users have their old password types. And everybody can log in! ;)

petru
  • 113
  • 2
  • 6
1

Many times this can happen if your MySQL server is using an old password hash, change the password or upgrade the server to get the latest password hash that fixes the authentication problem.

Clain Dsilva
  • 123
  • 5
  • 1
    I just changed the db user's password again, assuming MySql would use the new hash. It worked. No other changes were required. – eyal_katz Jul 26 '19 at 03:02
0

I had a similar message when trying to upgrade my mediawiki installation. I am using Netfirms as my hosting provider and I solved this by logging into the control panel, going the MySQL area and changing the database that mediawiki was using. I was then able to proceed with the mediawiki upgrade.