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
If you're using MySQL 8 or above, the default authentication plugin is caching_sha2_password, so to downgrade to mysql_native_password
(in case of PHP incompatibility), set it in my.cfg
, e.g.
[mysqld]
default-authentication-plugin=mysql_native_password
then restart MySQL service.
See: Upgrading to MySQL 8.0 : Default Authentication Plugin Considerations & Native Pluggable Authentication.
If still won't work, change the root password as suggested in the accepted answer, e.g.
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'root';
FLUSH PRIVILEGES;
Related:
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?
Your database server is set to use old passwords by default. The error message you get is mysqlnd seeing a database that can support the new (safer) authentication but refuses to do so. In such a case, mysqlnd aborts the connection and refuses to work.
Make sure your my.cnf does not have
old-passwords = 1
After you comment out that setting from my.cnf (or remove it from where else it might be set), and restart your server, make sure to re-set your password using the command VolkerK describes, otherwise you won't be able to log in.
I just had this problem with a Wordpress site that suddenly stopped working and displayed this error.
I found a GUI in the website's Control Panel that allowed me to change the password for the database user. I tried changing it to the current password and this was not allowed because the current password was not strong enough.
I changed the database password to a new, stronger password and edited my wp-config.php file to have the new password.
This worked!
So my guess is, the hosting provider upgraded something, maybe MySQL, to a version that requires stronger passwords. The fix for me was to use the cpanel GUI to change the database user's password, and update wp-config.php to match.