MySQL forgot root password

Source: Internet
Author: User
Tags mysql login

One, under the widows

1, first check whether the MySQL service is started, if it has been started to stop the service, can be run in the Start menu, using the command:
Start-to-menu->cmd->net stop MySQL
Open the first CMD1 window and switch to the MySQL bin directory.
Switch method: First find the MySQL directory, my directory is C:\Program Files (x86) \mysql\mysql Server 6.0\bin
Then run the command: CD C:\Program Files (x86) \mysql\mysql Server 6.0\bin Switchover succeeded
Then run the command:
Mysqld--defaults-file= "C:\Program Files (x86) \mysql\mysql Server 6.0\my.ini"--console--skip-grant-tables
Comments:
This command starts the MySQL service by skipping permission security checks, so that when you connect to MySQL, you do not have to enter a user password. The MySQL service is now open! The equivalent of creating a MySQL service thread yourself.
This window is reserved for not closing.
2, open the Second cmd2 window, also switch to the MySQL bin directory, connect MySQL:
Enter the command:
Mysql-u root-p
Appear:
Enter Password:
Enter the carriage directly here without entering the password.
Then there will be a login success message,
Use the command:
show databases;

To switch to the MySQL database using the command:
Use MySQL;

To change the root password using the command:
Update user set Password=password ("123456") where user= "root";
Tip: 123456 can change to a different password to see their preferences.

Refresh permissions:
Flush privileges;

And then quit.
Quit

You can turn off the previous Cmd1 window.
Then start the MySQL service
net start MySQL
Log in again, enter
Mysql-u root-p
Enter a password prompt, enter a new password to log in:
Enter Password: ******
Display Login Information: Success
Problem solving

Two, Linux method one

1. First verify that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily. Because the MySQL database is completely out of password-protected state during the reset of the root password of MySQL, other users can log in and modify the MySQL information arbitrarily. It is possible to implement the server's quasi-security state by enclosing 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 the login settings for MySQL:
# VI/ETC/MY.CNF
Add one sentence to the paragraph in [mysqld]: Skip-grant-tables Save and Exit VI.

3. Restart Mysqld
#/etc/init.d/mysqld Restart (Service mysqld restart)

4. Log in and modify the root password of MySQL

mysql> use MySQL;
mysql> UPDATE user SET Password = Password (' New-password ') WHERE user = ' root ';
mysql> flush Privileges;
Mysql> quit

5. Change MySQL login settings back
# VI/ETC/MY.CNF
Delete the skip-grant-tables you just added in the paragraph [mysqld]
Save and Exit VI.

6. Restart Mysqld
#/etc/init.d/mysqld Restart (Service mysqld restart)

7. Restore the server's normal working state

Reverse the action in step one. Restores the server's working status.

Third, Linux under Method two

1. Stop mysqld;
/etc/init.d/mysql stop
(You may have other ways to stop mysqld running anyway)

2. Start MySQL with the following command to start without checking permissions;
Mysqld--skip-grant-tables &

3. Then log in to MySQL using the root user with a blank password;
Mysql-u Root

4. Change the password of the root user;
mysql> Update Mysql.user Set Password=password (' NewPassword ') where user= ' root ';
mysql> flush Privileges;
Mysql> quit
Restart MySQL
/etc/init.d/mysql restart
You can log in with the new password newpassword.

One of the methods of each platform is a pro-test effective. Here, thank the great God for sharing.

MySQL forgot root password

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.