Forget mysql database connection password, how do?

principle

Simple and crude: change the password directly on the line.

Some may say that I am stupid, not to change the password you must first log in mysql? How can not get mysql to change the password? ? ?

Do not worry, read on! ! !

Okami operation

1
2
3
4
5
6
7
8
9
bin>net stop mysql
bin>mysqld --skip-grant-tables
bin>mysql
mysql>use mysql
mysql>update user set password=password("123456") where user="root";
mysql>flush privileges;
mysql>quit
bin>mysqladmin -u root -p shutdown
bin>net start mysql
If you can not be God, do not understand this command line is doing, please see the following Detailed graphics directly.

White Operation

Close the database

  • Under enter the mysql bin directory, open cmd, close the mysql database.

Markdown

Markdown

Skip to start certification authority database

Enter the following command and press Enter.

1
mysqld --skip-grant-tables

The --skip-Grant-the Tables  mean time skip start MySQL service certification authority table)

Note: At this time, just open a cmd window can not be used. Re-bin directory cmd to open a new window following the operation.

Markdown

Cmd window re-opened

  • Re-open a cmd window. Enter mysql Enter. Below is a graph showing the success.

Markdown

Permissions database connection

Use the following command to operate.

1
use mysql

Markdown

Modify the database connection password

1
update user set password=password("123456") where user="root";
Note: Here "123456" as a new password, according to their needs, enter a new password. Note that statement after the ";" can not miss.

Markdown

Refresh permission (must step)

1
flush privileges;

Markdown

Exit Database

Markdown

Use your new password database

After the change the root password, you need to perform the following statement and modify new password. Be wrong otherwise open mysql.
1
mysqladmin -u root -p shutdown

Markdown

Restart the database

Markdown

Guess you like

Origin www.cnblogs.com/wangchaonan/p/12084268.html