MySQL forgets the root password and does not restart mysqd to reset the root password

Source: Internet
Author: User
Tags flush localhost mysql reserved mysql database

Retrieve lost mysql root password
1. Start modifying the lost root password for a single mysql instance;
1. Stop mysql first
/Etc/init. d/mysql stop
2. Use -- skip-grant-tables to start mysql and ignore authorized logon verification.
Mysqld_safe -- skip-grant-tables -- user = mysql & -- prompt: add the -- skip-grant-tables parameter at startup, indicating that authorization verification is ignored.
3. Enter the database system
Shell> mysql
4. Modify the password of mysqlroot: update
Mysql> update mysql. user set password = password ("123456") where user = 'root' and host = 'localhost ';
Mysql> flush privileges;
Shell> mysqladmin-uroot-p123456 shutdown
5. Restart mysql
Shell>/etc/init. d/mysql start
Shell> mysql-uroot-p123456
2. Password loss for multiple instances:
1. Disable mysql
Mysqld_mu1_stop
2. Add the -- skip-grant-tables parameter at startup.
Mysqld_safe -- defaults-files =/data/mysql/mysql3377/mysql3377.cnf -- skip-grant-tables &
Mysql-uroot-p-S/tmp/mysql3377.sock <= logon password
3. Change the password:
Update mysql. user set password = password ("123456") where user = 'root'
Flush privileges;
4. Restart the service and log on with the new password:
Killall mysqld
Mysqld_muw.restart 3377


3. Do not restart mysqld

1. First, you must have a mysql database account with the modification permission, the current mysql instance account (the account with lower permissions, such as the account with the test database can be modified), or other accounts of instances of the same version. Copy the files related to the user table under the data/mysql directory to the data/test directory.

[Root @ localhost mysql] # cp mysql/user. * test/
[Root @ localhost mysql] # chown mysql. mysql test/user .*
2. Use another account with lower permissions to connect to the database and set the password data stored by the user in the test database.


[Root @ localhost mysql] # mysql-utest-p12345
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 17
Server version: 5.5.25a-log Source distribution

Copyright (c) 2000,201 1, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.

Type 'help; 'or' \ H' for help. Type' \ C' to clear the current input statement.

Mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-

Database changed
Mysql> update user set password = password ('ayun') where user = 'root ';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5 Changed: 0 Warnings: 0

Mysql>

3. Copy the modified user. MYD and user. MYI to the mysql Directory. Remember to back up the previous files.

Mv mysql/user. MYD mysql/user. MYD. bak
Mv mysql/user. MYI mysql/user. MYI. bak
Cp test/user. MY * mysql/
Chown mysql. mysql/user .*
4. Search for the mysql process number, send the SIGHUP signal, and reload the permission table.

[Root @ localhost mysql] # pgrep-n mysql
2184
[Root @ localhost mysql] #
[Root @ localhost mysql] # kill-SIGHUP 2184
5. Login test


[Root @ localhost mysql] # mysql-uroot-pyayun
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 20
Server version: 5.5.25a-log Source distribution

Copyright (c) 2000,201 1, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.

Type 'help; 'or' \ H' for help. Type' \ C' to clear the current input statement.

Mysql>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.