Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MySQL 5.7forget how to solve the root password

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

MySQL 5.7forgot how to solve the root password, and I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Close the running MySQL:

[root@www.woai.it ~] # service mysql stop

Running

[root@www.woai.it] # mysqld_safe-- skip-grant-tables &

For security reasons, remote connections can be prohibited like this:

[root@www.woai.it] # mysqld_safe-- skip-grant-tables-- skip-networking &

Use mysql to connect to server:

[root@www.woai.it] # mysql-p

Change the password:

Mysql > update mysql.user set authentication_string=password ('123qwe') where user='root' and Host =' localhost'

* A special reminder is that there is no Password field in the user table under the new version of mysql database.

Instead, the encrypted user password is stored in the authentication_string field

Mysql > flush privileges; mysql > quit

The modification is complete. Restart

[root@localhost ~] # service mysql restart

Then mysql can connect.

But at this time the operation seems to be not fully functional, but also alter user …

Mysql > alter user 'root'@'localhost' identified by' 123'

This is also possible:

Mysql > set password for 'root'@'localhost'=password (' 123')

The key point is to introduce mysql 5.7root password modification.

MySQL Manager password setting or modification:

According to the official instructions for versions later than 5.6, a random password with the file name of .mysql _ secret will be produced in the root directory every time you start.

[root@bright ~] # cat / root/.mysql_secret # Password set for user 'root@localhost' at 2015-03-27 23:12:10: Jj+FTiqvyrF [root@bright ~] # cd / usr/local/mysql/bin/ [root@bright bin] #. / mysqladmin-u root-h localhost password' 123456'-p

Enter password: # enter the second line in .MySQL _ secret for this line

Mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

Officially, no matter whether the author uses-- skip-grant-tables to start mysql or not, the test fails. Parents can test:

Shell > mysql-uroot-paired password'# password, that is, the password mysql > SET PASSWORD = PASSWORD ('newpasswd') in .MySQL _ secret

In the old version, ROOT does not have a password after installation, do the following:

Method 1:

Shell > service mysqld stop # stop mysql service shell > mysqld_safe-- skip-grant-tables & # start mysql shell > mysql-uroot-p # without enabling mysql shell mode, enter the command to enter, and enter the password prompt to enter directly. Mysql > use mysql; mysql > update user set password=PASSWORD ("123456") where user= "root"; # change password to newpassord mysql > flush privileges; # Update permissions mysql > quit # exit

Method 2:

Shell > service mysqld stop # stop mysql service shell > mysqld_safe-- skip-grant-tables & # start mysql shell > mysql-uroot-p # without enabling mysql shell mode, enter the command to enter, and enter the password prompt to enter directly. Mysql > set password for root@localhost = password ('mysqlroot')

Method 3:

Shell > / path/mysqladmin-u UserName-h Host password' new_password'-p

Reference: http://www.jb51.net/article/77858.htm

Solution for forgetting mysql root user password (skip-grant-tables)

Skip-grant-tables

As the name implies, when the database starts, jump permissions table restrictions, do not need to verify the password, directly log in.

Note:

This situation is only used if you forget the root password and have to restart the database. The current network environment is used with caution, the database needs to be restarted, and the security is difficult to guarantee.

1. Modify configuration parameters

/ etc/my.cnf

In

[mysqld] add the following:

Skip-grant-tables

Configuration item.

two。 Restart MySQL

Make the parameter take effect:

Service mysqld restart

3. Matters needing attention

At this time, all users login to the current database is password-free, so the security of the database is very low.

4. Modify the password

Specific methods:

Refer to the above introduction

5. Remove the parameters

a. Remove skip-grant-tables from the configuration file after the password has been changed

b. Restart the database again.

After reading the above, have you mastered how to solve the problem of MySQL 5.7forgetting root password? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report