Mysql登录出现"ERROR 1045 (28000)"

311 阅读1分钟

一.Mysql登录异常:

本地连接数据库报错,异常信息如下: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

二.解决步骤:

  1. 关闭mysql服务(Mac系统可直接在系统编号设置左下角mysql服务关闭即可);
  2. 打开终端,进入到mysql安装路径的bin目录,输入sudo su
  3. 此时命令行前缀会变成sh-3.2#,接着输入mysqld_safe --skip-grant-tables &,以安全模式进入数据库,会显示如下2行信息:
mysqld_safe Logging to '/usr/local/mysql/data/lyqdeMacBook-Pro.local.err'.
mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
  1. command+n重新打开新终端,输入/usr/local/mysql/bin/mysql并回车, 执行成功后会显示:
Your MySQL connection id is 433
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
  1. 接着输入use mysql;,会显示如下信息:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 
  1. 随后更新root密码update user set authentication_string=password('123456') where Host='localhost' and User='root';
  2. 执行成功后显示:
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1
  1. 最后exit;退出mysql终端,重启mysql服务即可.

三.参考博客:

blog.csdn.net/Cwsy_C/arti…

www.cnblogs.com/benbenzhu/p…