Home > Database > Mysql Tutorial > body text

mysql change root password

PHPz
Release: 2023-05-08 19:56:35
Original
1495 people have browsed it

MySQL is a widely used relational database management system. It provides a flexible, efficient, and secure data management and storage solution, allowing many developers and enterprises to easily store and manage their data. In fact, MySQL has become one of the most popular databases used in modern application development.

In MySQL database management, root is the default administrator account and has the highest authority of the database. Therefore, it is crucial to protect the security of the root account. In order to ensure the security of the database, you may need to change the password of the root account regularly. So, how to change the MySQL root password? This article will introduce in detail how to change the root password in MySQL.

  1. Stop the MySQL service

First, you must stop the MySQL service. Stopping the service avoids conflicts and errors during the password change process. In Linux environment, use the following command to stop the MySQL service.

sudo service mysql stop

  1. Start the MySQL service and skip permission verification

After the MySQL service is stopped, you need to restart the MySQL service, but you need Skips permission verification so that you can log in to MySQL without the root password. Here's how to start the MySQL service and skip permission verification.

sudo mysqld_safe --skip-grant-tables &

The --skip-grant-tables parameter in this command will allow you to start the MySQL service without providing the MySQL root password. In order to run the command in the background, the & symbol is required.

  1. Log in to MySQL and change the root password

After starting the MySQL service, you can now log in to MySQL using the MySQL command line. Log in to MySQL using the following command.

mysql -u root

Normally, you should not be able to log in to the MySQL service without entering a password, but since we skipped the authorization verification, you can log in to MySQL. After logging in, we need to change the password of the root account in the MySQL server.

Use the following command to change the root password.

mysql> use mysql;
mysql> update user set authentication_string=PASSWORD("your-new-password") where User='root';
mysql> flush privileges;
mysql> ; quit;

Replace "your-new-password" with your new password.

  1. Restart the MySQL service and test login

Now that the password of the MySQL root account has been changed, you can restart the MySQL service, and then try to use the new password to connect to the MySQL service.

Use the following command to restart the MySQL service.

sudo service mysql start

Now, try to connect to the MySQL service.

mysql -u root -p

You will need to enter a new password to log in to the MySQL service. If you successfully log in to the MySQL service, you have successfully changed the password of the MySQL root account.

Summary

MySQL is a popular database technology, and the root account is its default administrative account. Resetting the MySQL root password is an important means of ensuring database security.

In this article, we introduce in detail the method of changing the root password in MySQL. First, we need to stop the MySQL service and then start the MySQL service and skip the authorization verification. Next, we use the MySQL command line to log in to MySQL, change the root password, then restart the MySQL service and test the login.

But please note that once you reset the MySQL root password, make sure to record the new password in a safe place for future use. Also, strong passwords should be used to ensure database security.

The above is the detailed content of mysql change root 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