当前位置:网站首页>How to reset the password of MySQL root account

How to reset the password of MySQL root account

2022-07-04 22:22:00 Wu_ Candy

Share the theme today :mysql root How to reset the password of the account

I found it two days ago mysql The database suddenly fails to log in , But it was normal to use it last week , After some searching, the cause of the problem is still not found .

DBA Give me an explanation : I suspect that after the host restarts , Some documents (user.*) I lost it , I don't know why . I remember that you also encountered the same problem after restarting .

In this case , Had to reset root Account password . The specific operation steps are as follows

Step1: stop it mysql service

command :systemctl stop mysqld # Stop MySQL

command :systemctl status mysqld # Check the status

Step2: modify /etc/my.cnf To configure , add to skip_grant_tables=1 Startup settings , Pay attention to [mysqld] Add .

Step3: restart mysql And check the status

systemctl start mysqld systemctl status mysqld

Step4: Use mysql Command to connect to mysql The server , To reset root password

use mysql # Get into mysql database select * from user; # Inquire about user surface Check to see if there is root account number , If not, you need to operate as follows insert into sentence :

insert into `user` (`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`, `password_last_changed`, `password_lifetime`, `account_locked`) values('%','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','','0','0','0','0','mysql_native_password','*753ACFC7D5D71CB67C49345B035ADFAEA169594B','N','2021-03-08 11:00:04',NULL,'N');

If user There is... In the watch root account number , Then you can reset the password directly .

The order is as follows :update user set authentication_string=password('test123') where user='root'

FLUSH PRIVILEGES; # Refresh authorization list

Input again exit sign out mysql

Step5: Will step 2 in /etc/my.cnf Added to the file skip_grant_tables=1 Remove the startup setting , One more systemctl restart mysql Command restart mysql service .

Step6: The problem is solved when logging in again with the reset password .

end

原网站

版权声明
本文为[Wu_ Candy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207042157284927.html