MySQL root password forgotten solution under Linux

Source: Internet
Author: User

1. First verify that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily. Because the database is MySQL root completely out of password-protected state during the reset password, MySQL other users can log in and modify MySQL the information arbitrarily. The server's quasi-secure state can be implemented using a method that closes the MySQL external ports and stops Apache and all user processes. The safest state is to operate on top of the server Console and unplug the network cable.

2. Modify MySQL the logon settings:

# vi /etc/my.cnf 

In [mysqld] the paragraph, add one sentence: skip-grant-tables
For example:

[mysqld] datadir=/var/lib/mysql socket=/var/libskip

3. Restartmysqld

# /etc/init.d/mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK 

4. Login and modify MySQL the root password

#/usr/bin/mysqlWelcome to  theMySQL Monitor. Commands End  with; or \g. Your MySQL Connection ID is3  toServerversion:3.23. theType' help; ' or ' \h '  forHelp. Type' \c '  to Clear  theBuffer. mysql> use MySQL; Reading table Information forCompletion ofTable andColumn names can turn off this feature to Get aQuicker startup with-A Database changed mysql> UPDATE user SET Password = Password (' New-password ') WHERE User =' Root '; Query OK,0Rows Affected (0.00 sec) Rows matched:2Changed:0Warnings:0mysql> flush Privileges; Query OK,0Rows Affected (0.01 sec) Mysql> quit Bye

5. MySQLChange the login settings back

# vi /etc/my.cnf 

Add the deletion that you just [mysqld] added in the paragraph skip-grant-tables

6. Restartmysqld

# /etc/init.d/mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ]

Work for fun,live for love!

MySQL root password forgotten solution 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.