The solution for forgetting the root password of MySQL under Linux

Source: Internet
Author: User
Tags mysql login phpmyadmin

One of the recovery methods

1, first confirm the server out of security state, that is, no one can arbitrarily connect to MySQL database. 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, modify the MySQL login settings;

Add one sentence to the paragraph in [mysqld] :skip-grant-tables Save and exit Vim.

3. Restart mysqld;

Service mysqld Restart # or/etc/init.d/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, the MySQL login settings to change back;

Delete the skip-grant-tables that was added in the paragraph of [mysqld] just now;

Save and exit Vim.

6, restart mysqld;

Service mysqld Restart  # or/etc/init.d/mysqld restart

7, restore the normal working state of the server;

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

Two methods of recovery

If you forget the root password for MySQL, you can reset it in the following ways:

1. Kill the MySQL process in the system;

Killall-term mysqld

2, start MySQL with the following command, start without checking permissions;

Safe_mysqld--skip-grant-tables &   # Note: Press ENTER after execution

3, and then use a blank password to log in with the root user MySQL;

Mysql-u Root

4, modify the root user's password;

mysql> Update Mysql.user Set Password=password (' New password ') where user= ' root '; mysql> flush Privileges; Mysql> quit;

Restart MySQL and you will be able to log in with your new password.

Recovery method Three (recommended)

It is possible that your system does not have a SAFE_MYSQLD program (such as the Ubuntu OS I am using now, Apt-get installed MySQL), the following method can be restored

1, stop mysqld;

Service mysqld Stop  # or/etc/init.d/mysqld stop

(You may have other ways to stop mysqld running anyway)

2, start MySQL with the following command, start without checking permissions;

/usr/local/mysql/bin/mysqld--skip-grant-tables &

3, and then use a blank password to log in with the root user MySQL;

/usr/local/mysql/bin/mysql-u Root

4, modify the root user's password;

mysql> Update Mysql.user Set Password=password (' NewPassword ') where user= ' root '; mysql> flush Privileges; Mysql> quit;

Restart MySQL

Servcie mysqld Restart  # or/etc/init.d/mysql restart

You can log in with the new password newpassword.

Reference: http://lxsym.blog.51cto.com/1364623/477027

Practice Experience:

Somehow, when using the command

When setting the root secret to snsgou$123456 , the password is always a login failure!

When set to 123456 such as pure digital password, login success!

The following solutions/tips:

First set the root password to a relatively simple pure digital, such as 123456, and then through the phpMyAdmin tool to set the root password to a slightly more complex password! Done!

The SQL statement returned by PhpMyAdmin is:

SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' ********* ')

The reason why login failed after password change is now known:

The new password will take effect after restarting the MySQL service!

The solution for forgetting the root password of MySQL under Linux

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.