Connect to MySQL 4.1 with Old Authentication Using MySQLi
When attempting to establish a connection to a MySQL database with MySQLi, you may encounter the following error:
This error arises due to the use of an outdated password hashing scheme in MySQL versions preceding 4.1. While newer versions allow for the utilization of old passwords, it can lead to the aforementioned issue.
To resolve this problem, follow these steps:
Check Server Settings:
Execute the SQL query SHOW VARIABLES LIKE 'old_passwords'; to determine if the server defaults to the old password scheme (old_passwords,Off).
Identify Accounts with Old Passwords:
Use the query SELECT User`, `Host`, Length(`Password`) FROM mysql.user` to list user accounts and their password lengths. Accounts with a password length of 16 use the old scheme, while a length of 41 indicates new passwords.
Change Password for Old Accounts:
Update the passwords of accounts with old passwords using the statement SET PASSWORD FOR 'User'@'Host'=PASSWORD('yourpassword');. Remember to replace 'User' and 'Host' with the appropriate values from your query.
Flush Privileges:
Execute FLUSH PRIVILEGES; to apply the changes.
Verify Password Length:
Re-run the query from Step 2 to confirm that the password lengths are now 41.
By implementing these steps, you should be able to successfully connect to the MySQL database using MySQLi, even though it utilizes the old password scheme.
The above is the detailed content of How to Connect to MySQL 4.1 with Old Authentication Using MySQLi?. For more information, please follow other related articles on the PHP Chinese website!