1. 程式人生 > >msyql5.7 root賬戶誤刪恢復

msyql5.7 root賬戶誤刪恢復

root賬戶刪除 恢復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=‘%‘;

msyql5.7 root賬戶誤刪恢復