MySQL forgot root password solution under CentOS

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 theMySQL database is completely password-protected during the reset of the root password of MySQL
Status, other users can also log in and modify MySQL information arbitrarily. MySQL can be used to
and stop 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 the login settings for MySQL :
# VIM/ETC/MY.CNF
Add a sentence to the paragraph in [mysqld] :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 mysqld
# Service Mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]

4 . Log in and modify mysql root password
# 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;
Database changed
mysql> UPDATE user SET Password = Password ( "New-password ' ' WHERE User = ' root ';
Query OK, 0 rows Affected (0.00 sec)
Rows matched:2 changed:0 warnings:0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
Mysql> quit

5. Change MySQL login Settings Back
# VIM/ETC/MY.CNF
Delete The skip-grant-tables you just added in the paragraph [mysqld]
Save and exit vim

6. Restart mysqld
# Service Mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]


This article is from the "Success" blog, make sure to keep this source http://maxiaotian.blog.51cto.com/10824115/1716000

MySQL forgot root password solution under CentOS

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.