linux下 root 登录 MySQL 报错的问题
最近在centOS7上,通过yum安装了mysql,安装成功后,使用root登录,出现了如下报错:
ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:NO)
mysql版本为:Ver14.14Distrib5.7.10,forLinux(X86_64)usingEditLinewrapper
然而实际上并没有进行过root密码设置(不知道是不是安装过程有被忽略的地方?)。
对此就各种寻找答案,大致有下面一些情况:
有说root的随机密码位于/root/.mysql_secret中,但是我根本没有/root/.mysql_secret文件。有文章表示
>ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(using >password:NO):表示没有生成root的临时密码 > >ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(using >password:YES):表示生成了root的临时密码。
有些资料说root的默认密码为空,经过确认那是以前的老版本,Mysql5.6及以后版本出处于安全考虑,root密码已经不为空了。
最终找到对我来说有用的解决方案。
产生原因:
NowthatthepasswordMySQLhadgeneratedisexpired,theproblemisreducedtogettingthispasswordtoworkagain(1)orgenerateanewone(2).ThiscanbeaccomplishedbyrunningMySQLwiththeskip-grant-tablesoptionwhichwouldmakeitignoretheaccessrights:
解决方法:
StopyourMySQLserver. Addskip-grant-tablesattheendofthe[mysqld]sectionofmy.cnffileandsaveit. StartMySQLserver. Interminal,typemysql-uroot-ptogetintoMySQLcommandprompt. Inthecommandprompt,typeUSEmysql;togetintothemysqldatabasewhereitkeepsdatabaseusers. Type UPDATEuserSETpassword_expired='N'WHEREUser='root'; toletMySQLknowthepasswordisnotexpired(1)or UPDATEuserSETauthentication_string=PASSWORD('YourNewPassword'),password_expired='N'WHEREUser='root';
附上链接:UnabletoaccessMySQLafteritautomaticallygeneratedatemporarypassword
发布出来,供大家参考。