mysql Access denied for user ‘root’@’localhost’ (using password: YES)解决方法
今天在启动mysql时出现以下问题:
[root@www~]#mysql-uroot-p Enterpassword: ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:YES)
网上的答案是各种各样的,最终解决问题的方法总结为以下,好多都是没有设置初始密码造成此问题的。
解决方法如下:
[root@www~]#servicemysqldstop#先关闭mysql服务 Stoppingmysqld:[OK] [root@www~]#mysql ERROR2002(HY000):Can'tconnecttolocalMySQLserverthroughsocket'/var/lib/mysql/mysql.sock'(2) [root@www~]#mysql-uroot-p#关闭服务后又出现如下问题 Enterpassword: ERROR2002(HY000):Can'tconnecttolocalMySQLserverthroughsocket'/var/lib/mysql/mysql.sock'(2) [root@www~]#mysql-urootmysql#键入此命令进入mysql Readingtableinformationforcompletionoftableandcolumnnames Youcanturnoffthisfeaturetogetaquickerstartupwith-A WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis1 Serverversion:5.1.73Sourcedistribution Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>updateusersetpassword=password('123')whereuser='root'andhost='localhost';---->修改root的密码 QueryOK,1rowaffected(0.04sec) Rowsmatched:1Changed:1Warnings:0 mysql>flushpriviledge; ERROR1064(42000):YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear'priviledge'atline1 mysql>flushprivileges; QueryOK,0rowsaffected(0.00sec) mysql>\q Bye [root@www~]#mysql-uroot-p------>重新进入 Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis2 Serverversion:5.1.73Sourcedistribution Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>\q Bye
到此就完了!!