Four Methods of MySQL Modifying root Password Summary of of
- 2021-12-12 06:10:56
- OfStack
Method 1: Use the SET PASSWORD command
Log in to MySQL first.
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: user table is edited 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. Shut down the running MySQL service.
2. Open the DOS window and go to the mysql\ bin directory.
3. Enter mysqld-skip-grant-tables. -skip-grant-tables means to skip permission table authentication when starting the MySQL service.
4. Open another DOS window (because the DOS window just now can no longer move) and go to the mysql\ bin directory.
5. Enter mysql. If successful, the MySQL prompt will appear
>
.
6. Connect to the permissions database: use mysql; .
6. Change the password: update user set password = password ("123") where user = "root"; (Don't forget to add a semicolon at the end).
7. Refresh permissions (required step): flush privileges; .
8. Exit quit.
9. Log out of the system, re-enter, and log in using the user name root and the new password 123 just set.