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.