[英]Recovering MySql root@localhost user in mysql database
我偶然刪除了root @ localhost用戶,這是我后來發現mysql運行所需的權限,而現在,即使密碼正確,我也無法使用root登錄。 我嘗試在mysql ins afe模式下運行mysql:
/usr/bin/mysqld_safe --skip-grant-tables
然后以沒有密碼的root用戶身份登錄並進入mysql數據庫,在該數據庫中應執行以下命令:
create user root@localhost;
接着:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' with grant option;
commit;
FLUSH PRIVILEGES;
exit
但是當我嘗試使用上述命令創建用戶時,我得到:
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
有什么建議如何解決這個問題? 非常感謝您的幫助,謝謝!
編輯:解決方案
謝謝! 這解決了我的問題:
插入
mysql
。user
(Host
,User
,Password
,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
,ssl_type
,ssl_cipher
,x509_issuer
,x509_subject
,max_questions
,max_updates
,max_connections
,max_user_connections
)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','', '',``,'',``0'',``0'',``0'',``0'');
為了恢復事件的特權並觸發事件,我不得不訪問具有“全部”特權的另一個用戶,幸運的是,我擁有一個特權,但是沒有一個特權可能無法實現。
與重置相反,這應該可以恢復它。
停止mysql服務器。
編輯my.cnf以包括跳過授予
[mysqld]
skip_grant_tables
啟動mysql。 然后僅在提示符下使用mysql
命令登錄mysql。 然后插入此查詢,以確保在new password here
地方更新new password here
。
插入
mysql
。user
(Host
,User
,Password
,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
,ssl_type
,ssl_cipher
,x509_issuer
,x509_subject
,max_questions
,max_updates
,max_connections
,max_user_connections
)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','', '',``,'',``0'',``0'',``0'',``0'');
運行查詢后,停止mysql並從my.cnf中刪除跳過授權,然后重新啟動mysql
您是否嘗試通過ssh登錄? 在控制台中鍵入mysql -uroot之后:使用mysql; SELECT * FROM user
; 看看是什么列,然后執行INSERT INTO user
....
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.