MySQL Error: mysqld_safe: command not found error
mysqld_safe: command not found error
In MySQL 5.7 and prior versions, we are using mysqld_safe utility in-order to reset the root password.
But if we are trying the same method in MySQL 8 and later versions it will throw the above error.
So for resetting the root password in MySQL 8 and later versions we need to follow alternative method.
Step1: Stop MySQL service.
#systemctl stop mysqld
Step2: Set the MySQL environment variable.
#systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
Step3: Start MySQL service.
#systemctl start mysqld
Step4: Login to MySQL shell as root.
#mysql -u root
Step4: Update the root password using the following query.
>ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
Here we need to replace "NewPassword" with the required one.
Step5: Reload the privileges.
>FLUSH PRIVILEGES;
Step6: Exit from MySQL shell
>quit
Step7: Stop MySQL service.
#systemctl stop mysqld
Step9: Unset the MySQL environment variable that we configured earlier.
#systemctl unset-environment MYSQLD_OPTS
Step10: Start MySQL service.
#systemctl start mysqld
Now we can able to login with the updated root password.
That's all…