ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Posted on 2016-12-20 22:18 张鑫的园子 阅读(13954) 评论(0) 编辑 收藏 举报在安装好的MySQL服务器上,配置了环境变量之后,发现用mysql无法登录,报如题的错误,实在没有办法,决定用安全模式对root用户修改密码:
首先关闭正在运行的MySQL;
在一个终端窗口运行命令:mysqld_safe --user=mysql --skip-grant-tables --skip-networking&
[root@MySQL ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking&
运行之后新打开一个终端窗口:
[root@MySQL ~]# mysql -u root mysql
mysql> update mysql.user set authentication_string=password('mysql') where user = 'root'; Query OK, 1 row affected, 1 warning (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
以上是5.7版本的修改密码方式,在5.7中存储密码的字段不再是password了,变成了authentication_string,在5.7之前采用以下命令:
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
修改之后登陆成功:
[root@MySQL ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.9-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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>
标签:
MySQL
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用