MySQL is an open-source relational database management system that is widely used for web-based applications. It is a secure and robust database system that offers many features and functionalities. The root user is the superuser account in MySQL that has all privileges and rights to access and modify the data. It is important to change the MySQL root password periodically to enhance the security of your database system. In this article, we will discuss how to change the MySQL root password.
Step 1: Stop MySQL Server
The first step is to stop the MySQL server. You can do this by running the following command as a root user:
Sudo systemctl stop mysql
This command will stop the MySQL server and prevent any new connections from being established.
Step 2: Start MySQL Server in Safe Mode
The next step is to start the MySQL server in safe mode. This will allow us to reset the root password. You can do this by running the following command as a root user:
Sudo mysqld_safe –skip-grant-tables &
This command will start the MySQL server in safe mode with the –skip-grant-tables option, which allows us to log in without a password.
Step 3: Connect to MySQL Server
Now, we need to connect to the MySQL server using the root account. You can do this by running the following command:
Mysql -u root
This command will connect to the MySQL server using the root account without a password.
Step 4: Change MySQL Root Password
Once connected to the MySQL server, you can change the root password by running the following command:
ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘new_password’;
Replace new_password with your new password that you want to set.
Step 5: Flush Privileges and Exit MySQL
After changing the root password, you need to flush the privileges to apply the changes. You can do this by running the following command:
FLUSH PRIVILEGES;
Then, exit the MySQL prompt by running the following command:
Exit;
Step 6: Restart MySQL Server
You need to restart the MySQL server to apply the changes. You can do this by running the following command:
Sudo systemctl restart mysql
This command will restart the MySQL server and apply the new root password.
In this article, we have discussed how to change the MySQL root password. It is important to change the root password periodically to enhance the security of your database system. The steps involved in changing the MySQL root password are straightforward and easy to follow. By following these steps, you can change the root password and protect your database system from unauthorized access.