mysql誤刪root用戶恢復(fù)方法
裝完數(shù)據(jù)庫清理一些默認賬號的時候不小心把root刪除了,flush privileges 之后的新 root 忘了grant任何權(quán)限,查看mysqld選項里面有個 −−skip-grant-tables
#/usr/libexec/mysqld --verbos --help
mysql5.5手冊說明如下
--skip-grant-tables
This option causes the server to start without using the privilege system at all, which gives anyone with access to the server unrestricted access to all databases. You can cause a running server to start using the grant tables again by executing mysqladmin flush-privileges or mysqladmin reload command from a system shell, or by issuing a MySQL FLUSH PRIVILEGES statement after connecting to the server. This option also suppresses loading of plugins, user-defined functions (UDFs), and scheduled events. To cause plugins to be loaded anyway, use the --plugin-load option.
--skip-grant-tables is unavailable if MySQL was configured with the --disable-grant-options option. See Section 2.10.2, “Typical configure Options”.
mysqld_safe是Unix/Linux系統(tǒng)下的MySQL服務(wù)器的一個啟動腳本。這個腳本增加了一些安全特性,會在啟動MySQL服務(wù)器以后繼續(xù)監(jiān)控其運行情況,并在出現(xiàn)錯誤的時候重新啟動服務(wù)器。后臺啟動mysql
#mysqld_safe --skip-grant-tables &
如果沒有root賬戶就添加一個
INSERT INTO user SET User='root',Host='localhost',ssl_cipher='',x509_issuer='',x509_subject='';
直接輸入mysql連接并添加權(quán)限,這時候是不能使用grant命令的,只能用update
UPDATE user SET Select_priv='Y',Insert_priv='Y',Update_priv='Y',Delete_priv='Y',Create_priv='Y',Drop_priv='Y',Reload_priv='Y',Shutdown_priv='Y',Process_priv='Y',File_priv='Y',Grant_priv='Y',References_priv='Y',Index_priv='Y',Alter_priv='Y',Show_db_priv='Y',Super_priv='Y',Create_tmp_table_priv='Y',Lock_tables_priv='Y',Execute_priv='Y',Repl_slave_priv='Y',Repl_client_priv='Y',Create_view_priv='Y',Show_view_priv='Y',Create_routine_priv='Y',Alter_routine_priv='Y', Create_user_priv='Y',Event_priv='Y',Trigger_priv='Y',Create_tablespace_priv='Y',authentication_string='' WHERE User='root';
注意我用的是mysql是5.5版本,可能操作過程中sql語句或其他地方有不同,語句執(zhí)行完畢之后需要flush privileges ,還可能要重新登錄才行。
相關(guān)文章
MySQL?數(shù)據(jù)備份和數(shù)據(jù)恢復(fù)的實現(xiàn)
數(shù)據(jù)恢復(fù)的過程包括將備份文件導(dǎo)入到數(shù)據(jù)庫中、重建索引、應(yīng)用日志等,本文主要介紹了MySQL數(shù)據(jù)備份和數(shù)據(jù)恢復(fù)的實現(xiàn),感興趣的可以了解一下2023-08-08mysql Community Server 5.7.19安裝指南(詳細)
這篇文章主要介紹了mysql Community Server 5.7.19安裝指南(詳細),需要的朋友可以參考下2017-10-10MySQL——修改root密碼的4種方法(以windows為例)
本文以windows為例為大家詳細介紹下MySQL修改root密碼的4種方法,大家可以可以根據(jù)的自己的情況自由選擇,希望對大家有所幫助2013-07-07輕松上手MYSQL之SQL優(yōu)化之Explain詳解
Explain是SQL分析工具中非常重要的一個功能,它可以模擬優(yōu)化器執(zhí)行查詢語句,幫助我們理解查詢是如何執(zhí)行的,這篇文章主要給大家介紹了關(guān)于輕松上手MYSQL之SQL優(yōu)化之Explain詳解的相關(guān)資料,需要的朋友可以參考下2024-06-06MySQL學(xué)習(xí)之數(shù)據(jù)更新操作詳解
這篇文章我們將學(xué)習(xí)一下用于數(shù)據(jù)更改的 “UPDATE” 語句, “UPDATE” 語句也是屬于 DML 這一類數(shù)據(jù)庫操作語言,感興趣的可以了解一下2022-08-08