Enter current password for root (enter for none): ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
时间: 2023-11-17 12:03:47 浏览: 41
这个错误提示表明您正在尝试使用root用户登录MySQL,但是密码不正确或者没有权限。如果您忘记了密码,可以尝试重置密码。以下是两种方法:
1.使用mysqld_safe重置密码
```bash
# 停止MySQL服务
sudo systemctl stop mysql
# 使用mysqld_safe启动MySQL服务,并跳过权限验证
sudo mysqld_safe --skip-grant-tables &
# 连接到MySQL服务
mysql -u root
# 切换到mysql数据库
use mysql;
# 更新root用户的密码
update user set authentication_string=password('new_password') where user='root';
# 刷新权限
flush privileges;
# 退出MySQL服务
exit;
# 停止mysqld_safe服务
sudo pkill mysqld_safe
# 启动MySQL服务
sudo systemctl start mysql
```
2.使用mysql_secure_installation重置密码
```bash
# 运行mysql_secure_installation脚本
sudo mysql_secure_installation
# 选择重置密码选项并按照提示操作
```
相关问题
Enter current password for root (enter for none): ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
引用和中提到的错误"ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO/YES)"表示在使用root登录MySQL时,访问被拒绝。这个错误通常是由于密码问题导致的。在中提到的解决方法是在终端中使用mysql -u root -p命令登录MySQL,当需要输入密码时,直接按enter键即可不输入密码登录。然后,使用命令update user set password=password("你的新密码") where user="root";修改root用户的密码,再使用flush privileges;命令刷新权限,最后使用quit退出MySQL。
所以,如果你遇到了"Enter current password for root (enter for none): ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)"的错误,你可以尝试按照上述步骤进行操作,修改root用户的密码来解决这个问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [linux中ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)](https://blog.csdn.net/li2327234939/article/details/54289904)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [linux中的mysql数据库不能初始化,已解决](https://blog.csdn.net/qq_41342692/article/details/107458221)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [重置密码遇到ERROR 1045 (28000): Access denied for user root@localhost (using passwor:yes)问题](https://blog.csdn.net/qq_36564503/article/details/106991196)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
Enter password: ERROR 1045 (28000): Access denied for user root @ localhost (using password: YES)
这个错误提示表明您正在尝试使用root用户连接到MySQL数据库,但是密码不正确或者没有输入密码。请确保您输入的密码是正确的,并且在输入密码时没有输入任何额外的字符或空格。如果您不确定密码是否正确,可以尝试重置密码或者创建一个新的MySQL用户并授予所需的权限。
如果您已经确定密码是正确的,但是仍然无法连接到MySQL数据库,则可能是由于MySQL服务器配置问题导致的。您可以检查MySQL服务器的日志文件以获取更多信息,并尝试重新启动MySQL服务器以解决问题。
```shell
Enter password: *******
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
```