Home > Database > Mysql Tutorial > body text

Linux mysql change password

WBOY
Release: 2023-05-14 09:28:37
Original
1485 people have browsed it

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.

  1. Log in to the system as the root user

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
Copy after login

After entering the current user password, we logged in to the system as the root user.

  1. Start the MySQL service

Next, we need to start the MySQL service. We can start the service through the following command:

systemctl start mysql
Copy after login

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.

  1. Use the default password to log in to 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
Copy after login

When entering the password, we can directly press the Enter key so that we can log in to MySQL with the default password.

  1. Change 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';
Copy after login

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;
Copy after login
  1. Restart the MySQL service

Finally, we need to restart the MySQL service so that the new password takes effect. Use the following command to execute:

systemctl restart mysql
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template