簡體   English   中英

在MySQL數據庫中恢復MySql root @ localhost用戶

[英]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 userHostUserPasswordSelect_privInsert_privUpdate_privDelete_privCreate_privDrop_privReload_privShutdown_privProcess_privFile_privGrant_privReferences_privIndex_privAlter_privShow_db_privSuper_privCreate_tmp_table_privLock_tables_privExecute_privRepl_slave_privRepl_client_privCreate_view_privShow_view_privCreate_routine_privAlter_routine_privCreate_user_privssl_typessl_cipherx509_issuerx509_subjectmax_questionsmax_updatesmax_connectionsmax_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 userHostUserPasswordSelect_privInsert_privUpdate_privDelete_privCreate_privDrop_privReload_privShutdown_privProcess_privFile_privGrant_privReferences_privIndex_privAlter_privShow_db_privSuper_privCreate_tmp_table_privLock_tables_privExecute_privRepl_slave_privRepl_client_privCreate_view_privShow_view_privCreate_routine_privAlter_routine_privCreate_user_privssl_typessl_cipherx509_issuerx509_subjectmax_questionsmax_updatesmax_connectionsmax_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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM