一.Mysql登录异常:
本地连接数据库报错,异常信息如下:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
二.解决步骤:
- 关闭mysql服务(Mac系统可直接在系统编号设置左下角mysql服务关闭即可);
- 打开终端,进入到mysql安装路径的bin目录,输入
sudo su - 此时命令行前缀会变成
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
- 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>
- 接着输入
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>
- 随后更新root密码
update user set authentication_string=password('123456') where Host='localhost' and User='root'; - 执行成功后显示:
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 1
- 最后
exit;退出mysql终端,重启mysql服务即可.