In Linux, the root password of mysql is missing (three methods). mysqlroot

Source: Internet
Author: User

In Linux, the root password of mysql is missing (three methods). mysqlroot

One of the methods to restore the MySQL password

1. First confirm that the server is in a secure state, that is, no one can connect to the MySQL database at will. Because during the resetting of the MySQL root Password, the MySQL database is completely out of the password-free status, other users can also log on and modify the MySQL information at will. You can disable the external port of MySQL and stop Apache and all user processes to implement the quasi-security status of the server. The safest status is to operate on the server Console and unplug the network cable.

2. Modify MySQL Logon Settings:

# vi /etc/my.cnf 

In the [mysqld] section, add skip-grant-tables to save and exit vi.

3. Restart mysqld

# /etc/init.d/mysqld restart ( service mysqld restart )

4. log on to and modify the MySQL root Password

mysql> USE mysql ; mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ; mysql> flush privileges ; mysql> quit

5. Modify the MySQL Logon Settings.

# vi /etc/my.cnf 

Delete the skip-grant-tables added to the [mysqld] section.

Save and exit vi.

6. Restart mysqld

# /etc/init.d/mysqld restart  ( service mysqld restart )

7. restore the normal working status of the server

Perform the inverse operation in step 1. Restore the server's working status.

Method 2 of MySQL password recovery

If you forget the MySQL root Password, You can reset it using the following methods:

1. KILL the MySQL process in the system;

killall -TERM mysqld

2. Run the following command to start MySQL without checking its permissions;

safe_mysqld --skip-grant-tables &

3. Use the empty password to log on to MySQL as the root user;

mysql -u root

4. Modify the password of the root user;

Mysql> update mysql. user set password = PASSWORD ('new password') where User = 'root'; mysql> flush privileges; mysql> quit

Restart MySQL to log on with the new password.

MySQL password restoration method 3

It is possible that your system does not have the safe_mysqld Program (for example, I am using the ubuntu operating system, mysql installed with apt-get). The following method can be restored:

1. Stop mysqld;

/etc/init.d/mysql stop

(You may have other methods. Simply stop running mysqld)

2. Run the following command to start MySQL without checking its permissions;

mysqld --skip-grant-tables &

3. Use the empty password to log on to MySQL as the root user;

mysql -u root

4. Modify 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 use the new password newpassword to log on.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.