Mysql Forget password how to do (Windows Linux) _mysql

Source: Internet
Author: User
Tags flush mysql login password protection

First to introduce you to Windows MySQL forgotten password solution.

  The actual operation under Windows is as follows

1. Close the running MySQL.

2. Open the DOS window and go to the Mysql\bin directory.

3. Enter Mysqld--skip-grant-tables carriage return. If you don't get a hint, that's it.

4. Open a DOS window again (because the DOS window is already unable to move), go to the Mysql\bin directory.

5. Enter MySQL return, if successful, will appear MySQL prompt >

6. Connection rights database >use MySQL; (> is the original prompt, don't forget the last semicolon)

6. Change Password:> update user set Password=password ("520") where user= "root"; (Don't forget the last semicolon)

7. Refresh permissions (necessary steps) >flush privileges;

8. Exit > \q

9. Logout system, re-enter, open MySQL, use user name root and just set the new password 123456 login.

 First step

C:\Documents and SETTINGS\ADMINISTRATOR>CD D:\web\www.php100.com\Mysql\MySQL Se
Rver5.5\bin
C:\Documents and Settings\administrator>d:
D:\web\www.php100.com\Mysql\MySQL Server5.5\bin>mysqld--skip-grant-tables

Second Step

Microsoft Windows [version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.
C:\Documents and SETTINGS\ADMINISTRATOR>CD D:\web\www.php100.com\Mysql\MySQL Se
Rver5.5\bin
C:\Documents and Settings\administrator>d:
D:\web\www.php100.com\Mysql\MySQL Server5.5\bin>mysql
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 1
Server version:5.5.10 MySQL Community Server (GPL)
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark the Oracle Corporation and/or its
Affiliates. Names may trademarks of their respective
Owners.
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
mysql> use MySQL;
Database changed
mysql> Update user Set Password=password ("520") where user= "root";
Query OK, 1 row Affected (0.00 sec)
Rows matched:1 changed:1 warnings:0
mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)
Mysql> \q
Bye
D:\web\www.php100.com\Mysql\MySQL server5.5\bin>

below to introduce Linux under the MySQL root password forget solution

1. First, verify that the server is in a secure state, that is, no one can arbitrarily connect to the MySQL database.

Because the MySQL database is completely out of password protection during the reset of the MySQL root password, other users can also arbitrarily log in and modify MySQL information. The server's quasi-security status can be achieved by blocking MySQL's external ports and stopping Apache and all user processes. The safest state is to operate on the console of the server and unplug the network cable.

2. To modify MySQL login settings:

# VI/ETC/MY.CNF

In the paragraph of [mysqld], add a sentence: Skip-grant-tables

For example:

[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Skip-grant-tables

Save and Exit VI.

3. Reboot mysqld
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]

4. Log in and modify the MySQL root password

#/usr/bin/mysql
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 3 to server version:3.23.56
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the buffer.
mysql> use MySQL;
Reading table information for completion of table and column names
You can turn off the feature to get a quicker startup with-a
Database changed
mysql> UPDATE user SET Password = Password (' New-password ') WHERE user = ' root ';
Query OK, 0 rows Affected (0.00 sec)
Rows matched:2 changed:0 warnings:0
mysql> flush Privileges;
Query OK, 0 rows affected (0.01 sec)
Mysql> quit
Bye

5. Change the MySQL login settings back

# VI/ETC/MY.CNF
Delete the skip-grant-tables that you just added in the [mysqld] section
Save and Exit VI.

6. Reboot mysqld

#/etc/init.d/mysqld Restart
stopping mysql: [OK]
starting mysql: [OK]

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.