Home > Database > Mysql Tutorial > mysql user password modification

mysql user password modification

PHPz
Release: 2023-05-12 09:46:06
Original
25640 people have browsed it

MySQL is a common relational database management system with a wide range of application fields. It is widely used in websites, cloud computing environments, commercial applications, etc. Therefore, in the process of using it, the password Security is particularly important. This article will introduce how to change the MySQL user password.

1. Use the command line to change the password

Using the command line will be the easiest and easiest way to change the MySQL user password. The steps are as follows:

(1) Use the administrator account (root account) to change the password

First you need to log in to the MySQL server as an administrator. Generally, this is done through the root account. Assume that the password of the root account is 111111.

$ mysql -u root -p

(2) Enter the administrator password

Enter the initial password. Once correct, you will enter the MySQL command mode. Only then can the user password be modified.

(3) Switch to MySQL database

Switch to MySQL database.

use mysql;

(4) View the current user

Use the following command to view the current MySQL user and find the user whose password you want to change.

select user,host from user;

(5)Change the current user password

Use the following command to change the current user password, taking "I love MySQL" as an example, change Change it to MySQLLove.

set password for 'user'@'host' = password('MySQLLove');

Of course, "user" and "host" must be replaced with the user name and host name to actually modify the corresponding The user's password.

(6) Check whether the modification is successful

Enter the following command. After exiting, you can log in again with the modified password, and then use the previous command again to check whether the password is modified successfully.

exit;

2. Use phpMyAdmin to change the password

In addition to the command line, we can also complete the MySQL user password change through phpMyAdmin, a user-friendly web interface. This approach is often referred to as graphical operations.

The following are the specific steps:

(1) Open the phpMyAdmin web page

First open any web browser, and then enter "http://localhost/phpmyadmin" or " http://IP_address/phpmyadmin" (where the IP address is the IP address of the server where the MySQL database is located). At this time you can see the phpMyAdmin login page.

(2) Enter the username and password

Enter the initial username and password, and click the "Go" button to log in to the phpMyAdmin panel.

(3) Select the database and user

Select the database that needs to change the password, and then find the user who needs to change the password. This method is usually in the permissions tab. Here, modify the MYSQL user For example.

(4) Change the MySQL user password

Find the user that needs to be modified, and then click the "Edit User" button. In the pop-up window, find the item named "Change Password" and then modify the password field.

(5) Save the new password

Enter the new password and confirm, then save.

(6) Restart the MySQL service

You may need to execute the following command to restart the MySQL service:

$ service mysqld restart

3. Use the command line and name Pipeline and other technologies to restart the MySQL service

After modifying the MySQL user password, the MySQL service needs to be restarted for the new password to take effect. Here are the specific steps.

(1) Use the change authorization mode (chown) command to change the owner and ownership group of the MySQL data file.

sudo chown -R mysql:mysql /var/lib/mysql/

(2) Use the reset ROOT account password (mysql_reset_root_password) command.

sudo mysql_reset_root_password

(3) Restart the MySQL service.

sudo service mysql restart

Summary:

MySQL is a very powerful database management system. It is widely used in various fields around the world. Therefore, in the process of using MySQL, the password Security is particularly important, and how to change passwords is also a skill that must be learned. This article introduces three methods for changing MySQL user passwords. Through different methods, you can choose the most suitable modification method based on your experience or needs.

The above is the detailed content of mysql user password modification. 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