msyql5.7 root賬戶誤刪恢復

1.關閉數據:
/etc/init.d/mysql stop
2.啓動數據庫:
mysqld_safe --skip-grant-tables &
3.登錄數據庫,插入root用戶並設置權限:
mysql //無密碼登錄
mysql> use mysql
mysql> insert into user set user='root',ssl_cipher='',x509_issuer='',x509_subject='';
mysql> flush privileges;
4.給root用戶添加權限:
mysql> update user set Host='localhost',select_priv='y', insert_priv='y',update_priv='y',Alter_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',create_user_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' where user='root' and host='localhost';commit;
mysql> quit;
5.重啓數據:
/etc/init.d/mysql restart
6.登錄數據庫(無密碼登錄):
mysql

7.設置root密碼:
update mysql.user set password=password('newpassword') where user='root'

注把原有root賬戶改爲遠程登錄:
update user set host='192.168.30.130' where user='root' and host='%';

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章