mysql誤刪root用戶恢復方法_MySQL教程
推薦:MySQL編程中的6個實用技巧每一行命令都是用分號(;)作為結束 對于MySQL,第一件你必須牢記的是它的每一行命令都是用分號(;)作為結束的,但當一行MySQL被插入在PHP代碼中時,最好把后面的分號省略掉,例如: 代碼如下: mysql_query(INSERT INTO tablename(first_name,last_name)VALUES('$first_na
裝完數據庫清理一些默認賬號的時候不小心把root刪除了,flush privileges 之后的新 root 忘了grant任何權限,查看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系統下的MySQL服務器的一個啟動腳本。這個腳本增加了一些安全特性,會在啟動MySQL服務器以后繼續監控其運行情況,并在出現錯誤的時候重新啟動服務器。后臺啟動mysql
代碼如下:
#mysqld_safe --skip-grant-tables &
如果沒有root賬戶就添加一個
代碼如下:
INSERT INTO user SET User='root',Host='localhost',ssl_cipher='',x509_issuer='',x509_subject='';
直接輸入mysql連接并添加權限,這時候是不能使用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語句或其他地方有不同,語句執行完畢之后需要flush privileges ,還可能要重新登錄才行。
分享:Centos中徹底刪除Mysql(rpm、yum安裝的情況)我用的centos6,mysql讓我整出了各種問題,我想重裝一個全新的mysql,yum remove mysql-server mysql之后再install并不能得到一個干凈的mysql,原來的/etc/my.cnf依然沒變,datadir里面的數據已沒有任何變化,手動刪除/etc/my.cnf,/usr/lib/mysql,/usr/share/mysql,
- MySQL編程中的6個實用技巧
- Centos中徹底刪除Mysql(rpm、yum安裝的情況)
- Mysql修改datadir導致無法啟動問題解決方法
- mysql 查詢重復的數據的SQL優化方案
- mysql的左右內連接用法實例
- mysql中You can’t specify target table for update in FROM clau
- MySQL查詢和修改auto_increment的方法
- MySQL中的if和case語句使用總結
- Centos5.5中安裝Mysql5.5過程分享
- /var/log/pacct文件導致MySQL啟動失敗的案例分享
- MySQL中在查詢結果集中得到記錄行號的方法
- CentOS下php使用127.0.0.1不能連接mysql的解決方法
- 相關鏈接:
- 教程說明:
MySQL教程-mysql誤刪root用戶恢復方法
。