[Size = Small] [size = x-small] forgetting the mysqlroot password is a common problem in mysq usage. However, many friends do not reset the root password. At this time, errors such as login 5-acess denied for user: 'root' @ 'localhost' (usingpassword: Yes) will often occur. The reprinted Article below describes how to change the password.
1. Edit MySQL configuration file: My. ini
Generally, my. INI is the MySQL configuration file in the MySQL installation directory.
Add the following line at the end of the configuration file:
Skip-grant-tables
Save and exit editing.
2. Restart the MySQL service.
Run the following command line:
Net stop MySQL
Net start MySQL
3. Set a new root password.
Then run the following command in the command line:
Mysql-u root-P MySQL or MySQL-u root-P
Press enter to enter the database without a password.
At this point, execute use MySQL under the command line;
Run the following statement to update the root password:
Update user SET Password = PASSWORD ("root") where user = 'root ';
(Note: you do not need to use the mysqladmin-u root-P password 'your new password' command to change the password, because 'skip-grant-tables 'is configured,
If you don't believe it, you can try it out. It will certainly report the following error:
F: \ Documents and Settings \ long & gt; mysqladmin-u root-ppassword 'root'
Enter password:
Warning: single quotes were not trimmed from the password by yourcommand
Line client, as you might have expected.
Mysqladmin:
You cannot use 'Password' command as mysqld runs
With grant tables disabled (was started with -- skip-grant-tables ).
Use: "mysqladmin flush-Privileges password '*'" instead)
Exit to exit MySQL.
4. Restore the configuration file and restart the service.
Modify the MySQL configuration file and delete the added line 'skip-grant-tables.
Restart the MySQL service again and the password is changed.
Try the new password "root" and log on to MySQL again?
Some methods for changing the password of MySQL are provided:
1. Use the MySQL grant statement, such
Run the mysql-H hostname-u root command to log on to the mysqld server and run the grant command to change the password:
Mysql-H 192.168.1.101-u Root
The above 192.168.1.101 is an even mysqld running machine. You should replace it with your own. In this way, you can log on and change the password,
In fact, there is no need to be so troublesome, just use MySQL-u root.
Grant all on *. * To 'root' @ 'localhost' identified by 'root' withgrant Option
2. mysqladmin-u username-P old Password New Password
Example 1: Add a password root to the root user. Enter cmd, and then type
The following command indicates whether mysqladmin can be used in cmd,
Check whether "E: \ Program Files \ mysql server5.1 \ bin;" is added to your windows environment variable path. (change it to your own installation path .)
Mysqladmin-u Root Password Root
Note: because the root account does not have a password at the beginning, the old-P password can be omitted.
Example 2: Change the root password to admin.
Mysqladmin-u root-proot password Admin
Write the Code together. Otherwise, an error occurs. The error is as follows:
F: \ Documents ents and Settings \ long & gt; mysqladmin-u root-proot password Admin
Enter Password :****
Mysqladmin: Unknown command: 'root ')
You can also enter mysqladmin-u root-P password admin and press Enter,
Then, enter your old password. This is all right. It depends on your hobbies.
Example 3: remove the password of the root user.
F: \ Documents and Settings \ long & gt; mysqladmin-u root-ppassword;
Enter Password: Root
At this time, the root user has no password. You can set it using the following method:
F: \ Documents ents and Settings \ long & gt; mysql-u Root
MySQL & gt; Set password for 'root' @ 'localhost' = PASSWORD ('root'); (Syntax: set password for 'username' @ 'host' = PASSWORD ('Password '))
MySQL & gt; Set password for 'root' @ '%' = PASSWORD ('root ');
// This is optional. This is when the MySQL database is configured. If you choose to allow the root user to log in remotely, you are in the User table of the MySQL database,
Use MySQL;
Select * from user; two records are displayed. If this item is not configured, only the first record is displayed!
Host User Password
'Localhost', 'root', '* 9c9f3167129ecc3209d8550dc8b67156fdbf9418 ',...
'%', 'Root', '* 81f5e21e35407d884a6cd4a731aebfb6af209e1b ',...
With the above settings, the root password is changed to root, and the root user's root password is set.
3. Use MySQL;
Update user SET Password = PASSWORD ('yourpass') where user = 'root'
(Note: I have not tried the following methods. I don't know if it is correct. I just reprinted it.
The following methods are used at the MySQL prompt and must have the root permission of MySQL:
Method 4
MySQL & gt; insert into mysql. User (host, user, password)
Values ('%', 'Jeffrey ', password ('biscuit '));
MySQL & gt; flush privileges
Specifically, this is adding a user with the username Jeffrey and password biscuit.
I wrote this example in MySQL Chinese reference manual.
Be sure to use the password function, and then use flush privileges.
Method 5
Similar to method Sany, but the replace statement is used.
MySQL & gt; replace into mysql. User (host, user, password)
Values ('%', 'Jeffrey ', password ('biscuit '));
MySQL & gt; flush privileges
Method 6
Use the SET Password statement,
MySQL & gt; Set password for Jeffrey @ "%" = PASSWORD ('biscuit ');
You must also use the password () function,
However, you do not need to use flush privileges.
Method 7
Use the grant... identified by statement
MySQL & gt; grant usage on *. * To Jeffrey @ "%" identifiedby 'biscuit ';
Here, the password () function is unnecessary and does not need to be flush privileges.
Note: after a new user or password is set for MySQL, flush privileges is required to refresh the MySQL system permission table,
Otherwise, access is denied. Another way is to restart the MySQL server to make the new settings take effect.