问题描述:

在ubuntu14.04上安装完MYSQL后,MYSQL默认给分配了一个默认密码,但当自己在终端上使用默认密码登录的时候,总会提示一个授权失败的错误。

报错信息:Access denied for user 'root'@'localhost' (using password: YES)

执行过程:

sue@suepc:/usr/local/mysql$ mysql -u root -p

Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

解决方案:

重置root密码。

步骤如下:

1. 把mysql停止。

$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.

2. 启动mysqld_safe。

$ sudo mysqld_safe --skip-grant-tables &
[1] 28860

(如果遇到错误 

sue@suepc:~$ sudo mysqld_safe --skip-grant-tables &
[1] 7002
sue@suepc:~$ 2018-04-19T07:16:59.386922Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-04-19T07:16:59.475648Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql或mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

则执行下面命令后再次启动mysqld_safe。

(sudo mkdir -p /var/run/mysqld

sudo chown mysql:mysql /var/run/mysqld

)

3. 进入mysql,执行两条命令:

$ mysql -u root

mysql> UPDATE mysql.user SET authentication_string = PASSWORD('123456') , password_expired = 'N' WHERE User = 'root' AND Host = 'localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 1

mysql> update mysql.user set plugin="mysql_native_password";
Query OK, 1 row affected (0.00 sec)
Rows matched: 3  Changed: 1  Warnings: 0

注意Mysql 5.7版本要修改的字段为authentication_string,而不是Password。另外,plugin字段的值要置成"mysql_native_password"。

4. 退出mysql

5. 停止Mysql

$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service. 

$ sudo kill -9 $(pgrep mysql)

6. 再次启动mysql

$ sudo /etc/init.d/mysql start
[ ok ] Starting mysql (via systemctl): mysql.service.

再次用密码可以登录。登陆后退出mysql.

$ mysql -uroot -p
Enter password:

mysql> quit
Bye

解决mysql登录报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)问题的更多相关文章

  1. centos7 上安装mysql5.7后登录报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Yes 或者No)

    原文转载自以下链接:https://blog.csdn.net/keepd/article/details/77151006 安装完mysql后会有个临时密码去日志查看,但是查看登录修改密后还是不行 ...

  2. 升级到macOS 10.12 mysqlb报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    系统升级到macOS 10.12后启动mysql后,在终端输入mysql 报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' ...

  3. 【转载】重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor ...

  4. mysql安装在centos7报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    原文链接:http://blog.csdn.net/kuluzs/article/details/51924086 [问题]:mysql版本:5.7.13 首次在centos下安装MySQL,客户端连 ...

  5. 重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    出现报错: Warning: World-writable config file '/etc/my.cnf' is ignored // 该文件权限过高ERROR 1045 (28000): Acc ...

  6. 密码正确 mysql无法登陆 red7.3 上安装mysql5.6后登录报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passswd :yes)

    集群需要mysql存储元数据,就在前几天还运行好好的,突然就进不去了......还是太菜,遇到的bug少. 引起这种故障的原因有很多......第一个坑比较多,大部分用户也就用第一个就可以解决问题,我 ...

  7. CentOS命令登录MySQL时,报错ERROR 1045 (28000): Access denied for user root@localhost (using password: NO)错误解决方法

    1.停用mysql服务:# /etc/rc.d/init.d/mysqld stop 2.输入命令:# mysqld_safe --user=mysql --skip-grant-tables --s ...

  8. mac mysql连接报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    找了半天 又是kill进程,又是改设置文件,又是重启电脑,都不管用 翻到stackoverflow上的解决方案,实施成功: 原文链接:https://stackoverflow.com/questio ...

  9. Linux下登陆MySQL时遇到报错"RROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) "

    前言 作者在2021-07-21时遇到 linux下登陆MySQL时遇到报错"RROR 1045 (28000): Access denied for user 'root'@'localh ...

随机推荐

  1. Java框架之Spring02-AOP-动态代理-AspectJ-JdbcTemplate-事务

    AOP 动态代理 代理设计模式的原理:使用一个代理将原本对象包装起来,然后用该代理对象”取代”原始对象.任何对原始对象的调用都要通过代理.代理对象决定是否以及何时将方法调用转到原始对象上. 代理模式的 ...

  2. 【C_Language】---常用C语言控制台函数总结(持续更新)

    写了这么久的C程序,每次看到输出的结果都是从上往下排列的黑白框,有没有感觉很无聊啊?今天再次总结一个常用的控制台函数,能够帮助你做好一个好看的界面. 1.设置光标位置代码如下: int main(vo ...

  3. NETCore下IConfiguration和IOptions的用法

    NETCore下IConfiguration和IOptions的用法 https://www.cnblogs.com/RainingNight/p/strongly-typed-options-con ...

  4. MySql笔记(二)

    目录 MySQL笔记(二) 一幅画,一次瞬间的回眸,就在那次画展上,那个眼神,温柔的流转,还是那干净的皮鞋,一尘不染,俊朗的眉宇性感的唇,悄悄走近,牵手一段浪漫 MySQL笔记(二) 13.条件查询 ...

  5. Alibaba Nacos 服务发现组件集群部署

    前面学习了单机模式下的启动,生产环境中部署nacos肯定是使用集群模式cluster保证高可用. 官方文档的集群部署推荐使用VIP+域名模式,把所有服务列表放到一个vip下面,然后挂到一个域名下面. ...

  6. 【新书推荐】《ASP.NET Core微服务实战:在云环境中开发、测试和部署跨平台服务》 带你走近微服务开发

    <ASP.NET Core 微服务实战>译者序:https://blog.jijiechen.com/post/aspnetcore-microservices-preface-by-tr ...

  7. iocp性能分析

    网络上找iocp性能分析的文章很少,因工作关系,花了点时间特意从客观数据和理论角度分析了下iocp的性能 环境 CPU i7 4核8线程 1G网卡,echo方式测试(一个客户机模拟多个客户端模式,模拟 ...

  8. 第二阶段冲刺个人任务——six

    今日任务: 搭建网络服务器,上传数据库及程序. 昨日成果: 合并程序(统计团队博客).

  9. Frameworks.Entity.Core 5 EntityValidation

    Project.Core\Frameworks.Entity.Core\EntityValidation\ EntityValidation 1  数值验证DigitAttribute.cs Digi ...

  10. Go的切片:长度和容量

    虽然说 Go 的语法在很大程度上和 PHP 很像,但 PHP 中却是没有"切片"这个概念的,在学习的过程中也遇到了一些困惑,遂做此笔记. 困惑1:使用 append 函数为切片追加 ...