MySQL is a popular open source relational database management system that develops a secure and reliable environment to store and manage data. Many people are troubled by the default password during the installation and configuration of MySQL, especially under Linux systems. In the following article, we will show how to change the default password of MySQL in Linux.
First, in Linux, we need to log in to the system as the root user and start the MySQL service. Open the terminal and enter the following command to log in:
sudo su
After entering the current user password, we logged in to the system as the root user.
Next, we need to start the MySQL service. We can start the service through the following command:
systemctl start mysql
If an error occurs, it means that the MySQL service is not correctly installed or configured correctly. We need to check the installation and configuration of MySQL.
As mentioned before, MySQL has a default password by default. We can use the following command to log in to MySQL with the default password:
mysql -u root -p
When entering the password, we can directly press the Enter key so that we can log in to MySQL with the default password.
After logging in to MySQL, we can change the default password of MySQL. Here are the steps on how to change the password:
update mysql.user set authentication_string=password('NewPassword') where user='root';
In this command, we need to replace NewPassword with the new password we want to set. After changing the password, we need to refresh the permissions to make the changes take effect:
flush privileges;
Finally, we need to restart the MySQL service so that the new password takes effect. Use the following command to execute:
systemctl restart mysql
Now, we have successfully changed the default password of MySQL and restarted the MySQL service. From now on, we can use the new password to log in to MySQL.
Summary
Under Linux system, we can change the default password of MySQL through the above steps. Although these steps are somewhat complex, as long as we follow them, we can successfully change the password. In fact, changing the default password of MySQL is a very important step to ensure database security, because the default password is very easy to be hacked, leading to data leakage. Therefore, we should modify the default password of MySQL as soon as possible and change the password regularly to ensure the security of the database.
The above is the detailed content of Linux mysql change password. For more information, please follow other related articles on the PHP Chinese website!