This blog will demonstrate the method for changing the MySQL root password in Ubuntu 22.04. Let’s get started.
Changing MySQL root password in Ubuntu 22.04
For the purpose of changing the MySQL root password in Ubuntu 22.04, follow the given instructions.
Note: The given method for changing password only implies for MySQL version greater or equal to “8”.
Step 1: Check MySQL version
First thing you need to do is check the version of installed MySQL on your system:
As you can see, we have installed MySQL version “8.0.29”:
Step 2: Stop MySQL service
In the next step, utilize the below-given command for stopping the MySQL service:
Now, the MQL service is stopped:
Step 3: Check MySQL status
After stopping the MySQL service, verify its status with the help of the provided command:
The given output indicates that MySQL is currently inactive on our system:
Step 4: Skipping Networking and Grant Tables
MYSQL server should start without networking checks and granting tables. To do so, set the value of “MYSQLD_OPTS”:
Then head towards the next step.
Step 5: Start MySQL service
Utilize the following command for starting the MySQL service
MySQL service is now started:
Step 6: Check MySQL status
Again, check the status of the MySQL service to ensure that it is currently active and running on the Ubuntu 22.04 system:
Now head towards the next step.
Step 7: Log in to MySQL
Write out the provided command in terminal for loging in to MySQL account:
Step 8: Flush privileges
To change the MySQL root password, firstly, it is required to flush all privileges:
Step 9: Choose MySQL database
Then choose the MySQL database:
Step 10: Change MySQL root password
After doing so, utilize the “ALTER” command and specify the new password:
Step 11: Exit MySQL
Lastly, type “quit” to logout from the active MySQL shell:
Step 12: Reverting Database to its normal settings
In order to restart MySQL database back in “normal” mode, first of all, “revert” the added changes by unsetting the value of environment variable:
Next, revert “MySQL” for removing the set system configuration:
Step 13: Kill MySQL processes
Execute the following “killall” command to kill all MySQL processes:
Step 14: Restart MySQL service
In the final step, restart the MySQL service so that it can take changes from the configured settings:
Now, move to the next step.
Step 15: Log in to MySQL
Log in to MySQL by writing out the following command in Ubuntu 22.04 terminal and specify the password you have added with the “ALTER” command:
That’s it. You have successfully changed the password of MySQL:
We have compiled the easiest method for changing the MySQL root password in Ubuntu 22.04.
To change the MySQL root password in Ubuntu 22.04, firstly, stop the MySQL service and unset the value of the environment variable. After doing so, start the MySQL service, log in to the MySQL root account, flush all privileges, choose a database, and use the “ALTER” command to specify the new password. Lastly, revert the database back to the normal mode, restart the MySQL service, and log in with the new password. This blog demonstrated the method for changing the MySQL root password in Ubuntu 22.04.