We all know that the problem of changing the user password in MySQL has always been a nightmare for new users. In this case, new users often encounter errors, and eventually cannot access the MySQL database, so here are some examples to illustrate.
1. The original password is 123456.
- C:\>type MySQL5.bat
- @echo off
- MySQL -uroot -p123456 -P3306
The correct format for modifying the MySQL user password is:
We use
User: root can be changed to another one)
Password: woshiduide
To demonstrate the new password.
- C:\>MySQLadmin -uroot -p password woshiduide
- Enter password: ******
The modification is successful. Note that many spaces behind the PASSWORD keyword are modified as follows:
- C:\>MySQLadmin -uroot -p password ‘woshiduide’
- Enter password: ******
- C:\>MySQLadmin -uroot -p password ‘woshiduide’
- Enter password: *********
- Warning: single quotes were not trimmed from the password by your command
- line client, as you might have expected.
-
In this case, the real password is 'woshiduide'
- C:\>MySQL -uroot -p’woshiduide’
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 18
- Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)
- Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
- MySQL>
-
In actual operations on changing the password of a MySQL user, This is often the case for new users:
- C:\>MySQL -uroot -pwoshiduide
- ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: Y
- ES)
So it was very depressing. BAIDU and GOOGLE searched a lot.
Change the password.
- C:\>MySQLadmin -uroot -p’woshiduide’ password 123456
2. You can directly access MySQL and change the password.
- MySQL> use MySQL
- Database changed
- MySQL> update user set PASSWORDPASSWORD = PASSWORD(‘woshiduide’) where USER=’root’ and H
- OST=’localhost’;
- Query OK, 1 row affected (0.05 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
- MySQL> flush privileges;
- MySQL> exit
- Bye
- C:\>MySQL -uroot -pwoshiduide
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 23
- Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)
- Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
- MySQL>
- Query OK, 0 rows affected (0.02 sec)
3. Use the set password command to modify the PASSWORD:
- C:\>MySQL5.bat
- Enter password: ******
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 8
- Server version: 5.1.17-beta-community-nt-debug-log MySQL Community Server (GPL)
- Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
- MySQL> set password for root@’localhost’ = password(‘woshiduide’);
- Query OK, 0 rows affected (0.02 sec)
- MySQL> flush privileges;
- Query OK, 0 rows affected (0.09 sec)
- MySQL> exit
- Bye
4. GRANT is acceptable, but it is not described here. Because of permission issues.
The above content is an introduction to changing the user password of MySQL. I hope you will gain some benefits.