当前位置:Gxlcms > 数据库问题 > SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

时间:2021-07-01 10:21:17 帮助过:14人阅读

  • 安装 nextcloud 的时候选择的是 mysql ,在链接 mysql 的时候报错,信息如下:

    SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
    
  • 搜索了下应该是 MySQL 8默认使用了新的密码验证插件:caching_sha2_password ,而有些 PHP 版本不支持这个问题造成的

  • 解决办法:

    • 修改登录用户的 plugin 为 mysql_native_password

      mysql -uroot -p
      use mysql;
      ALTER USER ‘root‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY ‘密码‘;
      FLUSH PRIVILEGES;
      
    • 以上修改完成以后,本地链接没有问题,但是远程连接还是不行,需要修改 host 为 %

      update user set host = ‘%‘ where user =‘root‘;
      
    • 假如上一步修改不成功,提示有重复数据 Duplicate entry ‘%-root‘ for key ‘user.PRIMARY‘,删除其他的信息

      delete user where user=‘root‘ and host =‘%‘;
      
  • 以上可以解决了已建账号的密码认证问题

  • 确保新添加的用户可以正常使用,需要把配置文件修改了

    • 配置文件:/etc/mysql/my.cnf
    • 解决办法:打开该文件,在 [mysqld] 模块下面添加一句 default_authentication_plugin=mysql_native_password

SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

标签:requested   eth   root   delete   set   cat   lstat   sqlstate   host   

人气教程排行