MySQL Access denied for user 'root'@'localhost' 解决方法

  • 执行 mysql -uroot -ppassword 出现如下错误
ERROR 1045 (28000): Access denied for user 'root'@'localhost'

解决方法

  • 停止mysql
# service mysql stop
//or
# /usr/local/mysql/support-files/mysql.server stop
  • 安全模式启动
//找到mysqld_safe所在位置
# find /usr/local/mysql -name "mysqld_safe"
# mysqld_safe --skip-grant-tables --skip-networking &
  • 安全模式进入mysql
# mysql -u root
//password替换为你要修改的密码
mysql> UPDATE mysql.user SET PASSWORD=PASSWORD('password') WHERE USER='root';
  • 启动mysql,问题解决
# service mysql start
//or
# /usr/local/mysql/support-files/mysql.server start
    原文作者:oceandlnu
    原文地址: https://segmentfault.com/a/1190000014753491
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞