异常描述:
mysql 5.7因为误删除了mysql.localhost,导致无法通过mysql -uroot -p来进行登录
修改方法:
1.修改配置文件新增如下參數
skip-grant-tables
2.重啟數據庫
3.mysql登陸
set sql_log_bin=0;
INSERT INTO user SET User='root',Host='localhost',ssl_cipher='',x509_issuer='',x509_subject='';
update mysql.user set authentication_string=password('123456') where User='root'; //123456密碼請自己調整
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',Rcepl_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_tacblespace_priv='Y' where user='root' and host ='localhost';
set sql_log_bin=1;
4.修改配置文件注釋如下參數
skip-grant-tables
5.重啟數據庫