This article is a mirror article of machine translation, please click here to jump to the original article.

View: 11446|Reply: 0

[Source] mysql how to change the password of the root user

[Copy link]
Posted on 6/18/2019 1:47:30 PM | | |
Method 1: Use the SET PASSWORD command
First, log in to MySQL.
Format: mysql> set password for username@localhost= password('new password');
Example: mysql> set password for root@localhost = password('123');

Method 2: Use mysqladmin

format: mysqladmin -u username -p old password password new password
Example: mysqladmin -uroot -p123456 password 123

Method 3: Edit the user table directly with UPDATE

First, log in to MySQL.
mysql> use mysql;
mysql> update user set password=password('123') where user='root' and host='localhost';
mysql> flush privileges;

Method 4: When you forget the root password, you can do this

Take Windows as an example:
1. Close the running MySQL service.
2. Open a DOS window and go to the mysql\bin directory.
3. Type mysqld --skip-grant-tables into enter. --skip-grant-tables means skipping permission table authentication when starting the MySQL service.
4. Open another DOS window (because the DOS window is no longer movable) and go to the mysql\bin directory.
5. Enter MySQL enter, and if successful, the MySQL prompt > will appear.
6. Connect to the permission database: use mysql; .
6. Change password: update user set password=password("123") where user="root"; (Don't forget the last extra semicolon).
7. Refresh permissions (required step): flush privileges; .
8. Quit quit.
9. Log out of the system, re-enter, and log in with the username root and the new password 123 you just set.




Previous:User manual for the JCSHELL test tool
Next:Regular expression basics
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com