PDA

View Full Version : How to speed up manual process of resetting all MySQL passwords on WHM/cpanel server?



Fli
03-20-2018, 01:16 PM
How to automate manual task replacing legacy MySQL passwords by new ones on WHM/cPanel server and in user's .php files?
This task may be needed in case one migrate from old MySQL to new one. In such a case the mysql passwords are automatically reseted:


The system changed the password for the database user "myzom" to a random string because the original password used an old and insecure format that is incompatible with MySQL version 5.6.17. You must manually change the password for "username" to match the original password in order to ensure that applications that use the credentials will continue to function

leaving files with old outdated passwords, causing sites unable to connect MySQL. More about that here (http://linux-bash-script-find-reset-replace-legacy-mysql-passwords-in-files).
So how to as quickly as possible change all the passwords in files?

Here is the process:

1. Go to new server WHM into section SQL Services > Change MySQL User Password
2. Rewrite first mysql username to the following command which you will execute on the server command line:

grep -C 4 -Ri "userhere_name" /home/userhere/public_html

3. From the results of the above command, copy old password to some temporary place, example browser search box.
4. proceed with the password reset on WHM page opened in step 1 and copy also new password.
5. WHM will say: You have successfully changed “mysqlusername”’s MySQL password.
6. Replace old password by new one in files:

for file in $(find /home/userhere/public_html -type f);do sed -i "s|oldpassword|newpassword|g" 2>/dev/null;done

---
Another approach can be to create script to list all mysql users, find .php files that contain that mysql username and also phrase: "localhost" or 'localhost'
manually read and copy old password
Do password generating/reset command for the username
Do search and replace command in files to replace old copied password by new password.

If you find easier way to complete the process, please kindly share it.

kumkum
09-25-2021, 02:50 PM
If you want to reset MySQL root password then you can easily do this. It is must to have root access of server.
You have to reset MySQL root password on Centos server (https://hoststud.com/resources/how-to-reset-mysql-root-password-through-ssh-on-centos-linux-server.211/).