Asked 6 years ago
15 Jun 2017
Views 957
jessica

jessica posted

reset password of mysql server without knowing pervious password ?

i was trying to install composer for windows . its failed many time because of some extension not in PHP and lastly error was php version is not up to date .

but in this process of installing composer . suddenly my other localhost site is giving me error for database connection .

so i got that all users are deleted from mysql server. so i dont have any auth username password for server and now i want to create new user or reset if any exists pervious user for mysql .

so is that possible to reset password of mysql server without knowing pervious password ?
iPhone-coder

iPhone-coder
answered Apr 24 '23 00:00

If you need to reset the password of a MySQL server but you do not have access to the previous password, you can still reset the password if you have root user access to the server. Here's how you can do it:

1.Stop the MySQL service: Before making any changes to the MySQL configuration, you need to stop the MySQL service. You can do this by executing the following command as the root user:



sudo systemctl stop mysql
2.Start MySQL in safe mode: You can start MySQL in safe mode with the following command:


sudo mysqld_safe --skip-grant-tables &

This starts MySQL without password authentication, so you can reset the root password.

3.Connect to MySQL: You can connect to the MySQL server as the root user with the following command:


mysql -u root

4.Change the root password: Once you're connected to MySQL, execute the following command to change the root password:


UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';

Replace 'new_password' with the new password that you want to set.

5.Flush privileges: After changing the password, you need to execute the following command to flush the privileges and ensure that the changes take effect:


FLUSH PRIVILEGES;

6.Restart the MySQL service: Stop the safe mode instance of MySQL by pressing Ctrl + C, and then start the MySQL service again with the following command:


sudo systemctl start mysql

Once you've completed these steps, the MySQL root password will be reset to the new password you specified. Remember to keep the new password safe and secure.




Post Answer