当前位置:网站首页>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
边栏推荐
猜你喜欢
VS2019 C# release下断点调试
将QA引入软件开发生命周期是工程师要遵循的最佳实践
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
The use of complex numbers in number theory and geometry - Cao Zexian
能源势动:电力行业的碳中和该如何实现?
Machine learning notes mutual information
Concurrent network modular reading notes transfer
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
迷失在Mysql的锁世界
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
随机推荐
常用的开源无代码测试工具
QT - double buffer plot
凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer
KDD2022 | 什么特征进行交互才是有效的?
将QA引入软件开发生命周期是工程师要遵循的最佳实践
【Acwing】第58场周赛 题解
好用app推荐:扫描二维码、扫描条形码并查看历史
服装企业为什么要谈信息化?
不同环境相同配置项的内容如何diff差异?
File read write
Common shortcut keys for hbuilder x
Why do you have to be familiar with industry and enterprise business when doing Bi development?
HDU - 2859 Phalanx(DP)
Bizchart+slider to realize grouping histogram
Basic structure of PostgreSQL - table
Force buckle 3_ 383. Ransom letter
Interview question 01.08 Zero matrix
Short video system source code, click the blank space of the screen, the keyboard does not automatically stow
Locust性能测试 —— 环境搭建及使用
并发优化总结