Get the App
SLTechnology News&Howtos  ›  Database  › 

What if I forget the root password of mysql under linux?

Shulou Source: shulou.com Published: 2022-05-31 23:12:53 09月29日 Update

The purpose of this article is to share with you how to forget the root password of mysql under linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. First make sure that the server is in a secure state, that is, no one can connect to the MySQL database at will.

Because during the period of resetting the root password for MySQL, the MySQL database is completely unprotected by the password

In this state, other users can log in and modify MySQL information at will. You can use the MySQL pair

The external port is closed, and the quasi-security of the server is realized by stopping Apache and all user processes.

Status. The safest state is to operate on the server's Console and unplug the network cable.

2. Modify the login settings of MySQL:

# vi / etc/my.cnf

Add a sentence to the paragraph of [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

# / etc/init.d/mysqld restart

Stopping MySQL: [OK]

Starting MySQL: [OK]

4. Log in and change the root password of MySQL

# / 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 login settings of MySQL

# vi / etc/my.cnf

Delete the skip-grant-tables just added in the paragraph of [mysqld]

Save and exit vi.

6. Restart mysqld

# / etc/init.d/mysqld restart

Stopping MySQL: [OK]

Starting MySQL: [OK]

Thank you for reading! This is the end of the article on "how to forget the root password of mysql under linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Password status login security server service what to do content data database more users articles China plus not bad practical that is information password protection articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB Docker Shulou Information Redmi