I will go to the interview tomorrow. I want to see some MySQL instructions tonight. Although I have been using MySQL, I feel that I am doing some simple operations. As a result, I started to use MySQL-uroot-P. Enter Password: 123456 to connect to the MySQL database, and never change the password.
-Uroot-p123456 password ABC123; the command changed the password to "ABC123" and then re-connected to the database, it still reported: Access denied for user
'Root' @ 'localhost' (using password: Yes.
I found a lot of information online, probably because I didn't set permissions for root. I finally found a method. However, it is troublesome, but there is no way to do it. I cannot use my MySQL database without any help. Many developed applications are connected to MySQL databases.
The procedure is as follows:
Step 1: log on to the system as a system administrator;
Step 2: If the MySQL server is running, stop it. There are two methods: 1. Choose "start"> "Control Panel"> "Management Tools"> "services". Find the MySQL service to stop. 2: Right-click my computer-> Manage-> services and applications-> services, and find the MySQL service to stop. 3: CTRL + ALT + Delete-> Start Service Manager-> service, find MySQL service to stop. (This step is so simple. I wrote too much details and should not! Waste level !)
Step 3: select the outermost part of a hard disk to create a TXT file. Why? Because this txt is only used to help you solve this error, and the glorious task of solving the error is completed, you can sacrifice it vigorously. Don't feel pity, it has no life. For example, put in: C: \ mysql-init.txt. (We recommend that you use this TXT name instead of personalization. If you do not know anything about it, I have never tried it. This name is exactly the name of the MySQL process. Do not ask why it is called, computers in China cannot ask why. You just need to know why .) Enter a sentence:
Set password for 'root' @ 'localhost' = PASSWORD ('123 ');
The string of numbers below is my Reset Password, because this password is used by default in my myeclipse project. You just need to change the password you want.
Step 4: Enter the DOS command prompt: Start Menu-> Run->
CMD, and then CD to the directory where you installed mysql. Of course, my MySQL is buried deep, c: \ Program Files \ mysql \ MySQL Server 5.0 \ bin>. If you install MySql in another location, adjust the following commands. Run the following command at the doscommand prompt:
C: \ Program Files \ mysql \ MySQL Server 5.0 \ bin> mysqld-NT -- init-file = C: \ mysql-init.txt.
Step 5: start the service. The procedure is the same as step 2. When the server is started, run the "-- init-file" option (function: Read SQL commands from the specified file at startup) to change the root user password. When the server is successfully started, delete the c: \ mysql-init.txt. At this time, the TXT task is completed. If an error occurs in the mysqlserver, disable mysqld-nt.exe (the third method in step 2 can be found to disable the process ). Then restart it and OK.
Finally, you can use the password you set in step 3> MySQL
-Uroot-P is connected to the MySQL database.
But you will ask, do I have to make this mistake every time I change the password? Do I have to sacrifice a TXT file to change the password successfully? There is no command to fix this simple matter of changing the password, of course not. The specific method is to use this command> mysqladmin
-Uroot-p123456 password ABC123; Use this command to change the password> mysql-uroot
-P123456: log on, instead of entering the password with a line break. After logging on, add a permission statement to the end of the mysql> operator (many documents do not explain when to enter the following command, many people think that an error is reported when the password is entered immediately after the password is changed ):
Grant all on MySQL. * To 'root' @ 'localhost' identified by 'Password ';
The last password is the password of the root user you want to modify. I am "123456" here. I can use MySQL only next time I log on.
-Uroot-P. Enter Password: 123456 log on to the database.
In fact, the above is all nonsense. If you want to change the password, you can use the original password to log on and use any of the following commands to change the password, but you have to run the same command twice, for the first time, I used it as a password change, and for the second time as a permission assignment. This is not the case. You can> MySQL
-Log on to uroot-p123456. You can also choose mysql-uroot-P. Enter
Password: 123456. Newpassword is the new password.
Grant
All on mydb. * To newusername @ hostname identified by "newpassword ";
Grant usage on *. * To newusername @ hostname identified by "newpassword ";
Grant select, insert, update on mydb. * To newusername @ hostname identified by "newpassword ";
Grant update, delete on mydb. testtable to newusername @ hostname identified by "newpassword ";
That is:
Grant all onmysql .*
To 'root' @ 'localhost' identified by "newpassword ";
Grant usage on *. * To 'root' @ 'localhost' identified by "newpassword ";
Grant select, insert, update on mydb. * To 'root' @ 'localhost' identified by "newpassword ";
Grant update, delete on mydb. testtable to 'root' @ 'localhost' identified by "newpassword ";
If you try more on your computer, you will always find a solution. Don't try your company's computer and break down the database. Correct the error. Haha!