MySQL root password reset method (Pro-Test available) _mysql

Source: Internet
Author: User
Tags mysql login
Attention! #号后面是需要操作的地方.

1. Prerequisite Considerations

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 protected during the reset of the MySQL root password
State, other users can also arbitrarily log in and modify MySQL information. You can use the MySQL pair
Port is closed, and the method of stopping Apache and all user processes to implement the server's quasi-security
State. 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. Restart the Mysqld method as follows
#/etc/init.d/mysqld restart
Stoppingmysql: [OK]
Starting MySQL: [OK]

How to do other reboots

Service mysqld [Start/stop/reboot] Operation

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 oftable and column names
You can turn off the feature to get Aquicker startup with-a
Database changed
Mysql>update user SET Password = Password (' New-password ') WHERE user = ' root ';
Query OK, 0 rows Affected (0.00 sec)
Rowsmatched: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
Stoppingmysql: [OK]
Starting MySQL: [OK]

Root password reset succeeded!
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.