Home>Article>Database> Let’s talk about the four ways to change the password in MySQL (take a quick look for beginners)

Let’s talk about the four ways to change the password in MySQL (take a quick look for beginners)

青灯夜游
青灯夜游 forward
2022-11-01 19:31:49 8506browse

How to change the password in MySQL? The following article brings four methods for beginners to change MySQL passwords. I hope it will be helpful to everyone!

Let’s talk about the four ways to change the password in MySQL (take a quick look for beginners)

Method 1: Use the set password command

(1) First log in to MySQL:

(2) Change the password format to:

##set password for username@localhost = password( 'New password');Be sure not to forget the semicolon at the end,For example: we change the password to 123:

set password for root@localhost = password('123');
The following interface appears to indicate that the modification was successful :

Method 2: Use mysqladmin

Using mysqladmin, we do not need to log in first, but it needs to be the original password; we can modify it directly. The modified password format is:

mysqladmin -u username -p old password password new password, note that there is no - in front of password, For example: Let’s change the password to 123456:

mysqladmin -uroot -p123 password 123456
The following interface appears to indicate that the modification is successful

Method 3: Use update to directly edit the user table

(1) First log in to MySQL

(2) Then enter in sequence:

use mysql # 连接权限数据库 update user set password=password('521') where user='root' and host='localhost'; # 改密码 flush privileges; # 刷新权限
The following interface appears to indicate that the modification is successful:

Method 4: Forgot password processing method

1. Close the running MySQL service.

win r input:

services.mscPress Enter, find MySQL, and manually close the MySQL service

2. Open the DOS window and use the cd command to go to the bin directory of mysql: it is recommended to directly find the bin directory of mysql and enter cmd and press Enter

3. Enter
mysqld --skip-grant-tablesand press Enter .

--skip-grant-tables means

Skip the permission table authenticationwhen starting the MySQL service.

4.

Open another DOS window(The DOS window just now cannot be moved), go to the bin directory of mysql.5. Enter mysql and press Enter. If the above modification is successful, a prompt like mysql> will appear directly.
6. Connect to the permission database: use mysql
6. Change password: update user set password=password("123") where user="root";
7. Refresh permissions (required step): flush privileges; (
Don’t forget the semicolon)8.exit or ctrl c to exit and log in again

[Related recommendations:

mysql video tutorial

The above is the detailed content of Let’s talk about the four ways to change the password in MySQL (take a quick look for beginners). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete