Home > Database > Mysql Tutorial > 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)

青灯夜游
Release: 2022-12-26 20:09:37
forward
8721 people have browsed it

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');
Copy after login
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
Copy after login
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; # 刷新权限
Copy after login
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-tables and press Enter .

--skip-grant-tables means

Skip the permission table authentication when 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!

Related labels:
source:csdn.net
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