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

本文涉及的产品
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 初次安装mysql,net start mysql,然后输入mysql -u root -p,出现enter password,我直接点击回车,结果出现如果下错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)。

初次安装mysql,net start mysql,然后输入mysql -u root -p,

出现enter password,我直接点击回车,结果出现如果下错误:

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

或者在 my.cnf 配置了密码

提示错误:

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

解决方案

MySQL安装时默认的用户是root,这里的root是指数据库的用户,root密码一般在初始化MySQL时存放在你的日志文件中,日志文件的存放路径可以通过my.cnf文件进行自定义。

使用如下方法即可解决,本人已验证可行。

1.停止mysql数据库

/etc/init.d/mysqld stop
(或者直接 kill -9 [PID] 杀进程!)

2.执行如下命令

mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

3.使用root登录mysql数据库

mysql -u root mysql

4.更新root密码

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

最新版MySQL请采用如下SQL:

mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';

5.刷新权限

mysql> FLUSH PRIVILEGES;

6.退出mysql

mysql> quit

7.重启mysql

/etc/init.d/mysqld restart

8.使用root用户重新登录mysql

mysql -uroot -p
Enter password: <输入新设的密码newpassword>

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
5天前
|
数据库
Access denied for user ‘xxx’@‘localhost‘(using password:YES)
Access denied for user ‘xxx’@‘localhost‘(using password:YES)
|
4天前
|
关系型数据库 MySQL 数据库
mysql 中登录报错:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)ERROR
mysql 中登录报错:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)ERROR
|
19天前
|
关系型数据库 MySQL 数据库
【已解决】ERROR 1045 - Access denied for user ‘root‘@‘localhost‘ (using password: YES)
【已解决】ERROR 1045 - Access denied for user ‘root‘@‘localhost‘ (using password: YES)
65 0
|
11月前
|
Java
Access denied for user ''@'localhost' (using password: NO)问题的解决
Access denied for user ''@'localhost' (using password: NO)问题的解决
|
关系型数据库 MySQL 数据安全/隐私保护
|
安全 关系型数据库 MySQL
解决mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO/YES)
解决mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO/YES)
771 0
|
关系型数据库 MySQL 数据库
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
328 0
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
|
SQL 关系型数据库 MySQL
Access denied for user ‘root‘ @‘123.233.244.218‘(using password:YES)的解决方法
Access denied for user ‘root‘ @‘123.233.244.218‘(using password:YES)的解决方法
179 1
Access denied for user ‘root‘ @‘123.233.244.218‘(using password:YES)的解决方法
|
关系型数据库 MySQL 数据库连接
ERROR 1045 (28000): Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
ERROR 1045 (28000): Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
ERROR 1045 (28000): Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
|
关系型数据库 MySQL 数据安全/隐私保护
ERROR 1142 (42000): GRANT command denied to user ** 或 ERROR 1045 (28000): Access denied for user '**'@'localhost' (using password: YES)
ERROR 1142 (42000): GRANT command denied to user ** 或 ERROR 1045 (28000): Access denied for user '**'@'localhost' (using password: YES)
707 0