解决MySQL 8.0登录Access denied for user 'root'@'localhost' (using password: YES)
时间: 2023-09-20 11:10:43 浏览: 164
如果您在使用MySQL 8.0时遇到“Access denied for user 'root'@'localhost' (using password: YES)”错误,可以尝试以下步骤进行解决:
1. 检查用户名和密码是否正确。确保您正在使用正确的用户名和密码进行登录。
2. 检查MySQL服务器是否正在运行。您可以通过运行以下命令来检查MySQL服务器是否正在运行:
sudo systemctl status mysql
如果MySQL服务器没有运行,请使用以下命令启动MySQL服务器:
sudo systemctl start mysql
3. 检查MySQL服务器的版本是否与您的应用程序兼容。如果您的应用程序不支持MySQL 8.0,则可能无法连接到MySQL服务器。
4. 检查MySQL服务器是否允许来自特定IP地址的连接。您可以通过编辑MySQL服务器配置文件来配置此选项。打开MySQL配置文件my.cnf,找到bind-address选项,并将其设置为0.0.0.0,以允许来自任何IP地址的连接。
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
在[mysqld]下添加以下行:
bind-address = 0.0.0.0
5. 检查MySQL服务器是否允许远程连接。您可以通过编辑MySQL服务器配置文件来配置此选项。打开MySQL配置文件my.cnf,找到以下行:
# skip-networking
将其注释掉,以允许远程连接。
#skip-networking
6. 如果您已经尝试了以上步骤但仍无法解决问题,您可以尝试重置MySQL root用户的密码。请按照以下步骤操作:
1) 停止MySQL服务器:
sudo systemctl stop mysql
2) 使用以下命令启动MySQL服务器:
sudo mysqld_safe --skip-grant-tables &
3) 使用以下命令连接到MySQL服务器:
mysql -u root
4) 更新root用户的密码:
UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';
5) 刷新用户权限:
FLUSH PRIVILEGES;
6) 退出MySQL服务器:
exit
7) 停止MySQL服务器:
sudo systemctl stop mysql
8) 使用以下命令重新启动MySQL服务器:
sudo systemctl start mysql
现在,您可以使用新密码登录MySQL服务器了。
阅读全文
相关推荐


















