Viewed   219 times

I am getting the following error:

Database connection failed: mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password').

This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file

I using PHP 5.3.8 and MySQL 5.5.16 on my local machine and my host (media temple) is running PHP 5.3 MySQL 5.0.51a. The version on the live server is older than the one on my machine.

How do I fix this error and connect to MySQL from my local machine?

I know there are similar posts to this one but I have tried them all and none are working.

 Answers

4
  • Remove or comment old_passwords = 1 in my.cnf

Restart MySQL. If you don’t, MySQL will keep using the old password format, which will mean that you cannot upgrade the passwords using the builtin PASSWORD() hashing function.

The old password hashes are 16 characters, the new ones are 41 characters.

  • Connect to the database, and run the following query:

    SELECT user, Length(`Password`) FROM  `mysql`.`user`;
    

This will show you which passwords are in the old format, e.g.:

+----------+--------------------+
| user     | Length(`Password`) |
+----------+--------------------+
| root     |                 41 |
| root     |                 16 |
| user2    |                 16 |
| user2    |                 16 |
+----------+--------------------+

Notice here that each user can have multiple rows (one for each different host specification).

To update the password for each user, run the following:

UPDATE mysql.user SET Password = PASSWORD('password') WHERE user = 'username';

Finally, flush privileges:

FLUSH PRIVILEGES;

Source: How to fix "mysqlnd cannot connect to MySQL 4.1+ using old authentication" on PHP5.3

Thursday, August 4, 2022
4

Regarding, "I have also thought of creating another table and storing id numbers in whatever sequence we want to serve the content. - But I am not sure if this is actually a good idea."

It's not a good idea, it's a wonderful idea. Here is a skelton design. It ain't perfect, but it will get you started.

Table Exercise - ExerciseID, NameOfExercise, MeasuredIn, other fields you may want, . Sample values of NameOfExercise are push-up, measure in repetitions, and RunningOnTheSpot, measured in seconds.

Table Routine - RoutineId, NameOfRoutine, other fields you might want. Sample values are, Jane Fonda's Routine, Navy Seal Routine, and Old Fart's Routine.

Finally, table ExerciseRoutine. This is a many to may relationship. An exercise can be in more than routine and a routine can have more than one exercise. Fields would be, ExerciseID, RoutineID, Sequence, MeasuredInMultipler, and other fields you might want.

Here is some sample data.

ExerciseId, NameOfExercise,       MeasuredIn
1           Push Ups              repetitions
2           Running on the Spot   seconds
3           Jumping Jacks         repetitions

RoutineId, NameOfRoutine
1          Jane Fonda
2          Navy Seal

and finally

 RoutineID, ExerciseID, Sequence, MeasuredInMultipler
 1          2           1         60
 1          3           2         10
 2          1           1         500
 2          3           2         100

So the Jane Fonda routine is running on the spot for 60 seconds followed by 10 Jumping Jacks. Meanwhile, the Navy Seal Routine is 500 Push Ups followed by 100 Jumping Jacks

This approach allows you to have many routines, all independent of each other.

Thursday, September 15, 2022
 
3
  1. Open & Edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distro.
  2. Add skip-grant-tables under [mysqld]
  3. Restart Mysql
  4. You should be able to login to mysql now using the below command mysql -u root -p
  5. Run mysql> flush privileges;
  6. Set new password by ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
  7. Go back to /etc/my.cnf and remove/comment skip-grant-tables
  8. Restart Mysql
  9. Now you will be able to login with the new password mysql -u root -p
Tuesday, November 1, 2022
1

edit: This only applies if you are in control of the MySQL server... if you're not take a look at Mysql password hashing method old vs new

First check with the SQL query

SHOW VARIABLES LIKE 'old_passwords'

(in the MySQL command line client, HeidiSQL or whatever front end you like) whether the server is set to use the old password schema by default. If this returns old_passwords,Off you just happen to have old password entries in the user table. The MySQL server will use the old authentication routine for these accounts. You can simply set a new password for the account and the new routine will be used.

You can check which routine will be used by taking a look at the mysql.user table (with an account that has access to that table)

SELECT `User`, `Host`, Length(`Password`) FROM mysql.user

This will return 16 for accounts with old passwords and 41 for accounts with new passwords (and 0 for accounts with no password at all, you might want to take care of those as well).
Either use the user management tools of the MySQL front end (if there are any) or

SET PASSWORD FOR 'User'@'Host'=PASSWORD('yourpassword');
FLUSH Privileges;

(replace User and Host with the values you got from the previous query.) Then check the length of the password again. It should be 41 now and your client (e.g. mysqlnd) should be able to connect to the server.

see also the MySQL documentation: * http://dev.mysql.com/doc/refman/5.0/en/old-client.html
* http://dev.mysql.com/doc/refman/5.0/en/password-hashing.html
* http://dev.mysql.com/doc/refman/5.0/en/set-password.html

Friday, October 21, 2022
 
jfly
 
1

I'm not really clear on why this became an issue on my XAMPP installation, since I'm also running PHP 5.3.x on the server's local box and wasn't experiencing those issues there. However, it has to do with my mySQL server running in "old password" encryption mode. Newer versions of PHP won't allow those kinds of connections, so you need to update your mySQL server to use the newer password encryption. Here are the steps, assuming you have control over the mySQL server. If you don't, that falls out of the scope of my knowledge.

  1. locate the configuration file for the mysql server called my.cnf. I found mine at /etc/my.cnf. You can edit it with sudo nano /etc/my.cnf

  2. Look for a line that says old_passwords=1 and change that to old_passwords=0. You have now told the server that the next time it is run, and it is asked to encrypt a password using the PASSWORD() command, it use the new 41-character encryption rather than the 16-character 'old' style encryption

  3. Now you have to restart your mysql server / service. YMMV, but on Fedora that was easily done with sudo service mysqld restart. Check your OS' instructions for restarting the mysql daemon or service

  4. Now we have to actually edit our user table within mysql. So open up an interactive shell to mysql (on the server you can type mysql -uYourRootUsername -pYourRootPassword)

  5. Change to the mysql database. This is the database that holds all the good stuff for server operation and authentication. You must have root access to work with this database. If you get an 'access denied' you're SOL. Sorry. use mysql; will switch to that database

  6. Now we want to update the user that was giving you grief. Ultimately you'll probably want to update all your users, but for now, we're just focusing on the user that threw the error. update user set Password=password('YOUR_PASSWORD') where User='YOUR_USERNAME';

  7. Now you just need to tell mysql to use the new password for authentication when that user attempts to connect. flush privileges;.

You should be good to go!

Tuesday, November 29, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :