1. 程式人生 > >MySQL root誤刪除或錯誤配置後恢復,不用跑路,超級恢復,越級恢復,Access denied for user 'root'@'localhost'恢復

MySQL root誤刪除或錯誤配置後恢復,不用跑路,超級恢復,越級恢復,Access denied for user 'root'@'localhost'恢復

前言:剛才用WIN10/SERVER2012的預設輸入法打了個‘%’(全形),儲存,重啟然後悲劇了

處理方法:

1、停止mysql服務;

在mysql安裝目錄(windows是在ProgramData資料夾下)下找到my.ini;

在my.ini中找到以下片段[mysqld];

另起一行加入程式碼:skip-grant-tables 並儲存

 

2、啟動mysql服務,並登入mysql(無使用者名稱和密碼);

找到user表

2.1、誤刪除處理:加入root使用者,mysql.sys自己看情況

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
	('localhost', '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', '', _binary '', _binary '', _binary '', 0, 0, 0, 0, 'mysql_native_password', password('123456'), 'N', '2018-10-19 13:23:43', NULL, 'N'),
	('localhost', 'mysql.sys', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', '', _binary '', _binary '', _binary '', 0, 0, 0, 0, 'mysql_native_password', '*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE', 'N', '2018-10-19 13:23:40', NULL, 'Y');

2.2、錯誤配置處理:更新root使用者

UPDATE user set `Host`='localhost',`authentication_string`=password('123456') where `User`='root';

此步驟可以用視覺化編輯工具,如Heidisql,直接編輯處理

 

3、把my.ini剛才加入的那行刪除(# 註釋)並重啟服務

4、用root使用者登入,OK!