Solution for Mysql to forget the root password and change the root password (Summary), mysqlroot
One: three methods to change the root password
Method 1: use the set password command
First, log on to MySQL.
Format: mysql> set password for username @ localhost = password ('new password ');
Example: mysql> set password for root @ localhost = password ('20140901 ');
Method 2: Use mysqladmin
Format:mysqladmin -u
Username-p old password New password
Example:mysqladmin -uroot -p123456 password 123
Method 3: Use UPDATE to directly edit the user table
First, log on to MySQL.
mysql> use mysql; mysql> update user set password=password('123') where user='root' and host='localhost'; mysql> flush privileges;
Ii. Solution to forgetting the root password
The procedure is as follows:
1. Disable the running MySQL service -->net stop mysql
2. Open the DOS window and go to the mysql \ bin directory.
3. Inputmysqld --skip-grant-tables
Enter。--skip-grant-tables
This means that the permission table authentication is skipped when the MySQL service is started. Note that the skip is preceded by two "-" And the DOS window cannot be entered.
4. Open another DOS window and go to the mysql \ bin directory.
5. Enter mysql and press Enter. If yes, the MySQL prompt> will appear.
6. Connect to the permission Database: use mysql ;.
7. Change the password:
Update user set password = password ("123") where user = "root"; (do not forget the last plus points)
8. Refresh permission (required): flush privileges ;.
9. Exit quit.
10. log out of the system and log on again. Log On with the username root and the new password 123 you just set.
3. Solution to accidental deletion of root users
1. Disable the running MySQL service -->net stop mysql
2. Open the DOS window and go to the mysql \ bin directory.
3. Inputmysqld --skip-grant-tables
Enter。--skip-grant-tables
This means that the permission table authentication is skipped when the MySQL service is started. Note that the skip is preceded by two "-" And the DOS window cannot be entered.
4. Open another DOS window and go to the mysql \ bin directory.
5. Enter mysql and press Enter. If yes, the MySQL prompt> will appear.
6. Connect to the permission Database: use mysql ;.
7. Insert the root user into the user table:
mysql> insert into user set user='root',ssl_cipher=''x509_issuer='',x509_subject='';
8. Authorize the New root User:
mysql>update user set Host='localhost',select_priv='y', insert_priv='y',update_priv='y',
Alter_priv='y',delete_priv='y',create_priv='y',drop_priv='y',reload_priv='y',shutdown_priv='y',Process_priv='y',file_priv='y',grant_priv='y',References_priv='y',index_priv='y',create_user_priv='y',show_db_priv='y',super_priv='y',create_tmp_table_priv='y',Lock_tables_priv='y',execute_priv='y',repl_slave_priv='y',repl_client_priv='y',create_view_priv='y',show_view_priv='y',create_routine_priv='y',alter_routine_priv='y',create_user_priv='y' where user='root';
9. exit: mysql> exit; or mysql> quit
10. Restart the service: net start mysql
11. log on to the root user
The above is a small series of solutions for Mysql to forget the root password and change the root password. I hope it will help you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!