码迷,mamicode.com
首页 > 数据库 > 详细

【问题记录】ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

时间:2019-06-25 10:24:08      阅读:526      评论:0      收藏:0      [点我收藏+]

标签:错误   shared   err   ant   style   使用   oca   ons   方案   

一、问题描述

环境:MySQL 8.0 + Windows

由于密码错误或者其他原因导致无法连上MySQL服务,如下图:

技术图片

 

二、解决方案

解决该问题的具体步骤如下:

1.关闭MySQL服务

  以管理员权限运行cmd程序然后输入net stop mysql,或者运行services.msc 然后找到MySQL服务并停止运行;

2.跳过权限登录MySQL服务

  看了很多人的博客,写的都是找到my.ini文件然后在[mysqld]后添加skip-grant-tables,经测试无效。

  又查到有的说在cmd中运行mysqld –skip-grant-tables,实测在mysql8.0中已失效,现使用mysqld --console --skip-grant-tables --shared-memory,运行结果如下图:

技术图片

3.无密登录

  再打开一个cmd窗口,输入mysql -u root -p,然后回车,再回车(不输入密码),直接无密登录,如下图:

技术图片

4.修改密码

  修改密码所用的主要命令如下所示:

把密码设置为空:UPDATE mysql.user SET authentication_string=‘‘ WHERE user=‘root‘ and host=‘localhost‘;

查看USER表:select host,user,plugin,authentication_string from mysql.user;

以caching_sha2_password加密方式设置密码修改密码:ALTER user ‘root‘@‘localhost‘ IDENTIFIED WITH caching_sha2_password BY ‘root‘;

刷新:flush privileges;

5.重新登录

  把之前打开的cmd窗口关闭,然后以管理员权限运行cmd程序,再执行net start mysql。在MySQL服务开启成功之后,输入mysql -u root -p然后在输入密码,成功登录MySQL。

技术图片

 

【问题记录】ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

标签:错误   shared   err   ant   style   使用   oca   ons   方案   

原文地址:https://www.cnblogs.com/TM0831/p/11079415.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!