How can I forget the root password of mysql in linux?

Source: Internet
Author: User

How can I forget the root password of mysql in linux?

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 use MySQL to disable External ports and stop Apache and all user processes to achieve quasi-security 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.
For example:

[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock skip-grant-tables 

3. Restart mysqld

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

4. log on to 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 of table and column names You can turn off this feature to get a quicker startup with -A 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 Bye 

5. Modify the MySQL Logon Settings.

# vi /etc/my.cnf 

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

6. Restart mysqld

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

 

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.